{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4e8443ed",
   "metadata": {},
   "source": [
    "<font color=gray size=4> 2023-02-24 </font> \n",
    "\n",
    "<font color=gray size=4> Python 数据挖掘</font>\n",
    "\n",
    "<font color=gray size=4> 笔记：Kanekikeh </font>\n",
    "\n",
    "<font color=gray size=4> week01:文本图片一键式数据获取 </font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a0fce23",
   "metadata": {},
   "source": [
    "# 课程介绍\n",
    "\n",
    "* 本课程目标：数据挖掘（Web）+数据清洗+数据重塑+数据结论\n",
    "\n",
    "\n",
    "## [Pandas]\n",
    "\n",
    "-----\n",
    "\n",
    "> 1. [pandas cheat sheet 查询表](https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf)\n",
    "> 2. [pandas Getting started](https://pandas.pydata.org/getting_started.html)\n",
    ">> 1. 环境搭建\n",
    ">> 2. [Tutorials](https://jupyterlab.readthedocs.io/en/stable/user/interface.html)\n",
    ">> 3. [Books](https://amzn.to/3DyLaJc)\n",
    ">> 4. [Videos资源](https://jupyterlab.readthedocs.io/en/stable/user/interface.html)\n",
    "\n",
    "-----\n",
    "\n",
    "## [Requests-HTML]\n",
    "\n",
    "* [文档链接](https://requests.readthedocs.io/projects/requests-html/en/latest/)\n",
    "\n",
    "-----\n",
    "\n",
    "##### 本节课简单的概括为 pandas模块 和 Requests-Html模块 的介绍和体验\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1edac012",
   "metadata": {},
   "source": [
    "# 体验项目一（页面表格数据）\n",
    "\n",
    "* 核心模块体验(Pandas)\n",
    "\n",
    "> 1. pd.read_html() \n",
    ">> pandas 中的 read_html () 函数是将HTML的表格转换为 DataFrame 的一种快速方便的方法，这个函数对于快速合并来自不同网页上的表格非常有用。\n",
    "> 2. pd.groupby()\n",
    ">> pandas中的groupby函数是先将df [DataFrame] 按照某个字段进行拆分，将相同属性分为一组；然后对拆分后的各组执行相应的转换操作；最后输出汇总转换后的各组结果\n",
    "> 3. pd.to_excel()\n",
    ">> 使用to_excel ()函数将DataFrame导出到excel文件 要将单个对象写入excel文件, 我们必须指定目标文件名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "05312b23",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 首先引用pandas模块 为后续操作做准备\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e893f337",
   "metadata": {},
   "source": [
    "## 一、pd.read_html()\n",
    "\n",
    "* 参考文档：[read_html](https://pandas.pydata.org/docs/reference/api/pandas.read_html.html)\n",
    "> 1. Read HTML tables into a list of DataFrame objects."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f9a6bb55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[     0     1             2          3            4    5     6     7\n",
       " 0   排名  排名变化            企业  价值（亿元人民币）  价值变化（亿元人民币）   总部    行业  成立年份\n",
       " 1    1     0            抖音      13400       -10050   北京  社交媒体  2012\n",
       " 2    2     1        SpaceX       8400         1680  洛杉矶    航天  2002\n",
       " 3    3    -1          蚂蚁集团       8000        -2010   杭州  金融科技  2014\n",
       " 4    4     0        Stripe       4100        -2230  旧金山  金融科技  2010\n",
       " 5    5    11         Shein       4000         2680   广州  电子商务  2012\n",
       " 6    6    15            币安       3000         2010  马耳他   区块链  2017\n",
       " 7    7     1    Databricks       2500            0  旧金山   大数据  2013\n",
       " 8    8     3          微众银行       2200          200   深圳  金融科技  2014\n",
       " 9    9     2          京东科技       2000            0   北京  数字科技  2013\n",
       " 10  10    11  Checkout.com       1900          870   伦敦  金融科技  2012,\n",
       "       0      1           2   3    4      5          6\n",
       " 0   NaN     国家   独角兽数量（变化） NaN  NaN     城市  独角兽数量（变化）\n",
       " 1    1-     美国  625 (+138) NaN   1-    旧金山  176 (+25)\n",
       " 2    2-     中国   312 (+11) NaN   2↑     纽约  120 (+35)\n",
       " 3    3-     印度    68 (+14) NaN   3↓     北京    90 (-1)\n",
       " 4    4-     英国     46 (+7) NaN   4-     上海    69 (-2)\n",
       " 5    5-     德国    36 (+10) NaN   5↑     伦敦    39 (+8)\n",
       " 6    6↑    以色列     24 (+7) NaN   6↓     深圳    33 (+1)\n",
       " 7    7↓     法国     23 (+4) NaN   6↑   班加罗尔    33 (+5)\n",
       " 8    8-    加拿大     21 (+6) NaN   8↑     柏林    23 (+6)\n",
       " 9    9-     巴西     17 (+5) NaN   9↓     杭州    21 (-1)\n",
       " 10  10-     韩国     15 (+5) NaN   9-     巴黎    21 (+3)\n",
       " 11  11-    新加坡     12 (+5) NaN  11↑  帕洛阿尔托    19 (+7)\n",
       " 12  12↑     瑞典      8 (+4) NaN  11↑     广州    19 (+9)\n",
       " 13  12↑     日本      8 (+2) NaN  13↓    波士顿    17 (+5)\n",
       " 14  12↑   澳大利亚      8 (+3) NaN  14↓    山景城    15 (+3)\n",
       " 15  15↑     荷兰      7 (+4) NaN  14↑   特拉维夫    15 (+4)\n",
       " 16  15↓    墨西哥      7 (+2) NaN  14↑    圣保罗    15 (+5)\n",
       " 17  17↓     瑞士      6 (+2) NaN  17↓    芝加哥    13 (-2)\n",
       " 18  18↓  印度尼西亚      5 (-2) NaN  18↑     孟买    12 (+3)\n",
       " 19  18*     越南      5 (+4) NaN  18↑    新加坡    12 (+5)\n",
       " 20  18↑     挪威      5 (+3) NaN  18↓    古尔冈     12 (0)\n",
       " 21  21↓     芬兰      4 (+2) NaN  21↓  雷德伍德城     11 (0)\n",
       " 22  21↓    爱尔兰      4 (+2) NaN  21↑    洛杉矶    11 (+2)\n",
       " 23  23↓    阿联酋      3 (+1) NaN  21↓   圣马特奥     11 (0)\n",
       " 24  23↓   哥伦比亚      3 (+1) NaN  21↑     首尔    11 (+4)\n",
       " 25  23↓    奥地利      3 (+1) NaN  25↑   美国剑桥     9 (+2)\n",
       " 26  23↓    西班牙       3 (0) NaN  25*    奥斯汀     9 (+4)\n",
       " 27  23↓    土耳其      3 (+1) NaN  25*     丹佛     9 (+5)\n",
       " 28  23↓    菲律宾      3 (+1) NaN  25*     成都     9 (+4)\n",
       " 29  29↓     泰国       2 (0) NaN  29*    迈阿密     8 (+3)\n",
       " 30  29*    比利时      2 (+1) NaN  29*    华盛顿     8 (+3)\n",
       " 31  29↓   尼日利亚       2 (0) NaN  NaN    NaN        NaN\n",
       " 32  29↓     丹麦       2 (0) NaN  NaN    NaN        NaN\n",
       " 33  29*   爱沙尼亚      2 (+1) NaN  NaN    NaN        NaN\n",
       " 34  29*     智利      2 (+1) NaN  NaN    NaN        NaN\n",
       " 35  29↓    马耳他       2 (0) NaN  NaN    NaN        NaN\n",
       " 36  29*    立陶宛      2 (+1) NaN  NaN    NaN        NaN,\n",
       "      0    1          2      3   4    5      6          7      8   9     10  \\\n",
       " 0   NaN   城市  独角兽数量（变化）  占中国比例 NaN  NaN     城市  独角兽数量（变化）  占美国比例 NaN   NaN   \n",
       " 1    1-   北京    90 (-1)    29% NaN   1-    旧金山  176 (+25)    28% NaN   1.0   \n",
       " 2    2-   上海    69 (-2)    22% NaN   2-     纽约  120 (+35)    19% NaN   2.0   \n",
       " 3    3-   深圳    33 (+1)    11% NaN   3↑  帕洛阿尔托    19 (+7)     3% NaN   3.0   \n",
       " 4    4-   杭州    21 (-1)     7% NaN   4-    波士顿    17 (+5)     3% NaN   4.0   \n",
       " 5    5-   广州    19 (+9)     6% NaN   5↓    山景城    15 (+3)     2% NaN   5.0   \n",
       " 6    6↑   成都     9 (+4)     3% NaN   6↓    芝加哥    13 (-2)     2% NaN   5.0   \n",
       " 7    7↑   苏州     7 (+2)     2% NaN   7-  雷德伍德城     11 (0)     2% NaN   7.0   \n",
       " 8    7↓   南京     7 (-3)     2% NaN   7-   圣马特奥     11 (0)     2% NaN   7.0   \n",
       " 9    7-   香港      7 (0)     2% NaN   7↑    洛杉矶    11 (+2)     2% NaN   7.0   \n",
       " 10  10↓   青岛      5 (0)     2% NaN  10*     剑桥     9 (+2)     1% NaN  10.0   \n",
       " 11  NaN  NaN        NaN    NaN NaN  10*    奥斯汀     9 (+4)     1% NaN   NaN   \n",
       " 12  NaN  NaN        NaN    NaN NaN  10*     丹佛     9 (+5)     1% NaN   NaN   \n",
       " \n",
       "       11         12       13  \n",
       " 0     城市  独角兽数量（变化）  占其他国家比例  \n",
       " 1     伦敦    39 (+8)      10%  \n",
       " 2   班加罗尔    33 (+5)       9%  \n",
       " 3     柏林    23 (+6)       6%  \n",
       " 4     巴黎    21 (+3)       6%  \n",
       " 5    圣保罗    15 (+5)       4%  \n",
       " 6   特拉维夫    15 (+4)       4%  \n",
       " 7    新加坡    12 (+5)       3%  \n",
       " 8    古尔冈     12 (0)       3%  \n",
       " 9     孟买    12 (+3)       3%  \n",
       " 10    首尔    11 (+4)       3%  \n",
       " 11   NaN        NaN      NaN  \n",
       " 12   NaN        NaN      NaN  ,\n",
       "     0     1           2             3   4    5     6           7   \\\n",
       " 0  NaN    行业  独角兽数量占中国比例          代表企业 NaN  NaN    行业  独角兽数量占美国比例   \n",
       " 1  1.0  健康科技         10%       联影医疗、微医 NaN  1.0  软件服务         14%   \n",
       " 2  1.0  人工智能         10%     小马智行、文远知行 NaN  2.0  金融科技         11%   \n",
       " 3  3.0  电子商务          9%  Shein、车好多、得物 NaN  3.0  健康科技          9%   \n",
       " 4  3.0   半导体          9%    集创北方、歌尔微电子 NaN  4.0  人工智能          8%   \n",
       " 5  5.0  软件服务          6%      小红书、58同城 NaN  4.0  网络安全          8%   \n",
       " 6  5.0  企业服务          6%     京东产发、行云集团 NaN  NaN   NaN         NaN   \n",
       " 7  NaN   NaN         NaN           NaN NaN  NaN   NaN         NaN   \n",
       " \n",
       "                            8   9    10    11            12  \\\n",
       " 0                        代表企业 NaN  NaN    行业  独角兽数量占其他国家比例   \n",
       " 1       Rippling, Notion Labs NaN  1.0  金融科技           23%   \n",
       " 2  Stripe, Citadel Securities NaN  2.0  电子商务           17%   \n",
       " 3          Devoted Health, Ro NaN  3.0   区块链            6%   \n",
       " 4         Grammarly, Talkdesk NaN  3.0  软件服务            6%   \n",
       " 5            Tanium, Lacework NaN  5.0    游戏            4%   \n",
       " 6                         NaN NaN  5.0    物流            4%   \n",
       " 7                         NaN NaN  5.0  网络安全            4%   \n",
       " \n",
       "                       13  \n",
       " 0                   代表企业  \n",
       " 1  Checkout.com, Revolut  \n",
       " 2     J&T Express, Kavak  \n",
       " 3                币安, FTX  \n",
       " 4            Canva, Snyk  \n",
       " 5   Dream11, Moon Active  \n",
       " 6           Forto, Loggi  \n",
       " 7         1Password, Wiz  ,\n",
       "      0     1      2          3            4   5     6     7\n",
       " 0   排名  排名变化     企业  价值（亿元人民币）  价值变化（亿元人民币）  总部    行业  成立年份\n",
       " 1    1     0     抖音      13400       -10050  北京  社交媒体  2012\n",
       " 2    2     0   蚂蚁集团       8000        -2010  杭州  金融科技  2014\n",
       " 3    3     3  Shein       4000         2680  广州  电子商务  2012\n",
       " 4    4     0   微众银行       2200          200  深圳  金融科技  2014\n",
       " 5    5    -1   京东科技       2000            0  北京  数字科技  2013\n",
       " 6    6    -3   菜鸟网络       1800         -470  杭州    物流  2013\n",
       " 7    7    -1    小红书       1300            0  上海  软件服务  2013\n",
       " 8    8     0     大疆       1200          130  深圳   机器人  2006\n",
       " 9    9    24   联影医疗       1040          700  上海  健康科技  2010\n",
       " 10  10    -1   元气森林       1000            0  北京  食品饮料  2016,\n",
       "        0      1        2         3\n",
       " 0    NaN     国家  全球GDP排名  GDP（亿美元）\n",
       " 1    1.0    俄罗斯       11     14830\n",
       " 2    2.0  沙特阿拉伯       20      7000\n",
       " 3    3.0     波兰       21      5970\n",
       " 4    4.0   委内瑞拉       25      4820\n",
       " 5    5.0     埃及       31      3650\n",
       " 6    6.0     南非       39      3350\n",
       " 7    7.0   孟加拉国       40      3230\n",
       " 8    8.0   巴基斯坦       44      2630\n",
       " 9    9.0   罗马尼亚       46      2490\n",
       " 10  10.0    葡萄牙       48      2290,\n",
       "      0    1           2      3\n",
       " 0  NaN   地区   独角兽数量（变化）  总价值占比\n",
       " 1   1-   北美  654 (+145)    46%\n",
       " 2   2-   亚洲   462 (+51)    40%\n",
       " 3  3 -   欧洲   159 (+45)    12%\n",
       " 4  4 -   南美     24 (+8)     1%\n",
       " 5  5 -  大洋洲      9 (+4)     1%\n",
       " 6  6 -   非洲      4 (+1)   0.2%,\n",
       "        0                   1          2    3      4     5\n",
       " 0    NaN                  企业  价值（亿元人民币）   国家     行业  成立年份\n",
       " 1    1.0  Citadel Securities       1500   美国   金融科技  2001\n",
       " 2    2.0                Miro       1170   美国   企业服务  2011\n",
       " 3    3.0                  滴滴        965   中国   共享经济  2012\n",
       " 4    4.0          The CrownX        550   越南    消费品  2019\n",
       " 5    5.0              Dunamu        535   韩国    区块链  2012\n",
       " 6    6.0                远景动力        430   中国    新能源  2019\n",
       " 7    7.0              KuCoin        420  塞舌尔    区块链  2017\n",
       " 8    8.0    iCapital Network        400   美国   金融科技  2013\n",
       " 9    9.0                广汽埃安        390   中国  新能源汽车  2017\n",
       " 10  10.0     RELEX Solutions        380   芬兰   企业服务  2005\n",
       " 11  10.0  The Boring Company        380   美国     建筑  2016,\n",
       "           0     1             2\n",
       " 0    排名（变化）    行业   独角兽数量占比（变化）\n",
       " 1    1 (+1)  金融服务   18% (+5.9%)\n",
       " 2    2 (-1)  企业管理   17% (-6.1%)\n",
       " 3    3 (+1)  医疗健康  9.6% (+3.2%)\n",
       " 4    4 (-1)    零售   8.7% (-10%)\n",
       " 5    5 (+1)  网络安全     5% (+19%)\n",
       " 6    6 (-1)    物流  4.6% (+4.5%)\n",
       " 7     7 (0)    运输  3.3% (-5.7%)\n",
       " 8    8 (+1)    能源   2.8% (+56%)\n",
       " 9        9*   半导体          2.1%\n",
       " 10    9 (0)  食品饮料   2.1% (+17%)\n",
       " 11  11 (-2)    教育  1.9% (+5.6%)\n",
       " 12  11 (-3)  消费电子   1.9% (-30%)\n",
       " 13  13 (+1)    游戏     1.5% (0%)\n",
       " 14  14 (-5)    汽车   1.4% (-22%)\n",
       " 15  15 (+2)   房地产  1.3% (-7.1%)\n",
       " 16      15*    航天  1.3% (+8.3%)\n",
       " 17  17 (-3)  生命科学   1.2% (-20%)\n",
       " 18  18 (-4)  传媒娱乐     1% (-33%)\n",
       " 19  18 (-5)    酒店     1% (-38%)\n",
       " 20  18 (-1)    传播     1% (-29%),\n",
       "           0     1          2      3\n",
       " 0    排名（变化）    行业  独角兽数量（变化）  总价值占比\n",
       " 1     1 (0)  金融科技  168 (+29)  17.6%\n",
       " 2    2 (+1)  电子商务   127 (+5)   9.1%\n",
       " 3     2 (0)  软件服务   127 (-7)     9%\n",
       " 4    4 (+1)  健康科技   97 (+17)   5.3%\n",
       " 5    5 (-1)  人工智能   94 (+10)   5.7%\n",
       " 6     6 (0)  网络安全   61 (+21)   3.3%\n",
       " 7    7 (+1)   区块链   52 (+22)   5.4%\n",
       " 8       8 *  企业服务   40 (+22)   2.1%\n",
       " 9       8 *    物流    40 (+8)   3.1%\n",
       " 10  10 (-3)  生物科技    37 (+6)   1.9%,\n",
       "           0         1          2           3\n",
       " 0    排名（变化）      主营业务  独角兽数量（变化）  总价值（亿元人民币）\n",
       " 1     1 (0)      在线市场    70 (+3)       13000\n",
       " 2     2 (0)        支付    41 (-2)       22000\n",
       " 3     3 (0)      数字银行    25 (+5)        4100\n",
       " 4        4*      网络安全         17        2400\n",
       " 5        5*       云安全         16        2700\n",
       " 6    5 (+1)      在线教育    16 (+3)        2400\n",
       " 7    7 (+1)     云数据服务    15 (+4)        1800\n",
       " 8        7*        保险         15        2200\n",
       " 9        7*    人力资源管理         15        2800\n",
       " 10  10 (-6)      生物制药     14 (0)        1400\n",
       " 11  10 (-3)  虚拟货币交易平台         14        7400,\n",
       "        0               1          2      3   4\n",
       " 0   成立年份              企业  价值（亿元人民币）     行业  国家\n",
       " 1   2022        MSquared         67    区块链  英国\n",
       " 2   2021            极氪汽车        600  新能源汽车  中国\n",
       " 3   2021    Sierra Space        300     航天  美国\n",
       " 4   2021       Yuga Labs        265    区块链  美国\n",
       " 5   2021       Autograph        250    区块链  美国\n",
       " 6   2021   Aleph Holding        135     传媒  美国\n",
       " 7   2021      ClickHouse        135    大数据  美国\n",
       " 8   2021        Saks.com        135   电子商务  美国\n",
       " 9   2021            洛轲智能        135  新能源汽车  中国\n",
       " 10  2021            星空华文        110     娱乐  中国\n",
       " 11  2021            JOKR         80     快递  美国\n",
       " 12  2021         Phantom         80    区块链  美国\n",
       " 13  2021   Candy Digital         75   金融科技  美国\n",
       " 14  2021      GlobalBees         75     投资  印度\n",
       " 15  2021       Anthropic         67   人工智能  美国\n",
       " 16  2021           Aptos         67    区块链  美国\n",
       " 17  2021         Emplifi         67    云计算  美国\n",
       " 18  2021  LayerZero Labs         67    区块链  美国\n",
       " 19  2021    Mensa Brands         67     投资  印度,\n",
       "       0                    1            2     3  \\\n",
       " 0   NaN                 投资机构  上榜独角兽数量（变化）  创立国家   \n",
       " 1    1-                 红杉资本    234 (+28)    美国   \n",
       " 2    2↑                   软银    180 (+34)    日本   \n",
       " 3    3↓               老虎环球基金    169 (+22)    美国   \n",
       " 4    4↑                   腾讯     90 (+22)    中国   \n",
       " 5    5-     Insight Partners     89 (+18)    美国   \n",
       " 6    6↓                Accel     85 (+11)    美国   \n",
       " 7    7-  Andreessen Horowitz     84 (+14)    美国   \n",
       " 8    8*         Y Combinator     80 (+22)    美国   \n",
       " 9    9↑               Coatue     78 (+11)    美国   \n",
       " 10  10↓                   高盛      75 (+4)    美国   \n",
       " \n",
       "                                   4  \n",
       " 0                           主要全球合伙人  \n",
       " 1                 Roelof Botha, 沈南鹏  \n",
       " 2                  Junichi Miyakawa  \n",
       " 3     Scott Shleifer, Chase Coleman  \n",
       " 4                               刘炽平  \n",
       " 5                       Jeff Horing  \n",
       " 6   Jim R. Swartz, Arthur Patterson  \n",
       " 7                      Ben Horowitz  \n",
       " 8                Jessica Livingston  \n",
       " 9                  Kris Fredrickson  \n",
       " 10                    David Solomon  ,\n",
       "            0        1                        2              3\n",
       " 0     排名（变化）     投资机构                 Investor  上榜中国独角兽数量（变化）\n",
       " 1         1-     红杉中国            Sequoia China       103 (+7)\n",
       " 2     2 (+3)     中金资本                     CICC       71 (+41)\n",
       " 3     3 (+1)       腾讯                  Tencent       55 (+14)\n",
       " 4     4 (-1)    IDG资本              IDG Capital         50 (0)\n",
       " 5     5 (-3)     高瓴资本        Hillhouse Capital        44 (-8)\n",
       " 6         6*     中信资本                    CITIC             35\n",
       " 7         7-     经纬中国    Matrix Partners China        29 (+5)\n",
       " 8     8 (+4)     阿里巴巴                  Alibaba       28 (+10)\n",
       " 9     9 (-3)     启明创投  Qiming Venture Partners        26 (+1)\n",
       " 10    9 (+2)       软银                 Softbank        26 (+7)\n",
       " 11       11*  CPE源峰资本           CPE Investment             25\n",
       " 12   12 (-4)     云锋基金               YF Capital        24 (+2)\n",
       " 13   13 (-4)     纪源资本              GGV Capital        23 (+3)\n",
       " 14   13 (+1)     五源资本               5Y Capital        23 (+6)\n",
       " 15   15 (-6)     顺为资本          Shunwei Capital         20 (0)\n",
       " 16   16 (+7)     君联资本           Legend Capital       19 (+12)\n",
       " 17   16 (+7)       小米                   Xiaomi       19 (+12)\n",
       " 18   16 (+7)      淡马锡                  Temasek       19 (+12)\n",
       " 19   16 (-1)     鼎晖投资                      CDH        19 (+4)\n",
       " 20   20 (-3)  SIG海纳亚洲                      SIG        16 (+5)\n",
       " 21       20*     元禾控股                    Oriza             16\n",
       " 22       20*      深创投                     SCGC             16\n",
       " 23       20*     建银国际        CCB international             16\n",
       " 24   20 (+9)     钟鼎资本     Eastern Bell Capital       16 (+10)\n",
       " 25       25*       中银                      BOC             14\n",
       " 26       25*     松禾资本       Green Pine Capital             14\n",
       " 27  27 (-15)     真格基金                Zhen Fund        13 (-5)\n",
       " 28       27*     源码资本      Source Code Capital             13\n",
       " 29       27*       春华                Primavera             13\n",
       " 30       27*     基石资本                 Co-stone             13,\n",
       "       0     1         2   3     4    5          6   7     8     9           10\n",
       " 0    NaN    国家  全球瞪羚数量占比 NaN   NaN   国家  全球独角兽数量占比 NaN   NaN    国家  世界500强数量占比\n",
       " 1    1.0    美国       38% NaN   1.0   美国        48% NaN   1.0    美国         49%\n",
       " 2    2.0    中国       32% NaN   2.0   中国        24% NaN   2.0    中国          9%\n",
       " 3    3.0    印度        7% NaN   3.0   印度         5% NaN   3.0    日本          6%\n",
       " 4    4.0    英国        5% NaN   4.0   英国         4% NaN   4.0    英国          5%\n",
       " 5    5.0    德国      2.4% NaN   5.0   德国         3% NaN   5.0    德国          4%\n",
       " 6    6.0   以色列      1.8% NaN   6.0  以色列         2% NaN   6.0    法国        3.8%\n",
       " 7    6.0   新加坡      1.8% NaN   7.0   法国       1.8% NaN   7.0   加拿大        3.4%\n",
       " 8    6.0    法国      1.8% NaN   8.0  加拿大       1.6% NaN   8.0    瑞士          3%\n",
       " 9    9.0   加拿大      1.1% NaN   9.0   巴西       1.3% NaN   9.0    印度        2.4%\n",
       " 10  10.0    瑞士        1% NaN  10.0   韩国       1.1% NaN  10.0  澳大利亚        2.2%\n",
       " 11  10.0  澳大利亚        1% NaN   NaN  NaN        NaN NaN   NaN   NaN         NaN,\n",
       "      0     1         2   3    4     5          6   7    8     9           10\n",
       " 0   NaN    城市  全球瞪羚数量占比 NaN  NaN    城市  全球独角兽数量占比 NaN  NaN    城市  世界500强数量占比\n",
       " 1   1.0   旧金山       11% NaN  1.0   旧金山        13% NaN  1.0    纽约          6%\n",
       " 2   2.0    上海       10% NaN  2.0    纽约         9% NaN  2.0    伦敦        3.4%\n",
       " 3   3.0    北京        7% NaN  3.0    北京         7% NaN  2.0    东京        3.4%\n",
       " 4   4.0    纽约        6% NaN  4.0    上海         5% NaN  4.0   旧金山          3%\n",
       " 5   5.0    伦敦      4.7% NaN  5.0    伦敦         3% NaN  5.0    巴黎        2.8%\n",
       " 6   6.0    深圳      4.5% NaN  6.0    深圳       2.5% NaN  6.0    北京        1.8%\n",
       " 7   7.0    杭州      2.9% NaN  6.0  班加罗尔       2.5% NaN  6.0   圣何塞        1.8%\n",
       " 8   8.0  班加罗尔      2.7% NaN  8.0    柏林       1.8% NaN  8.0  圣克拉拉        1.6%\n",
       " 9   9.0    苏州      1.8% NaN  9.0    杭州       1.6% NaN  8.0   芝加哥        1.6%\n",
       " 10  9.0   波士顿      1.8% NaN  9.0    巴黎       1.6% NaN  8.0    孟买        1.6%\n",
       " 11  9.0   新加坡      1.8% NaN  NaN   NaN        NaN NaN  NaN   NaN         NaN,\n",
       "     0     1         2   3    4     5          6   7    8      9           10\n",
       " 0  NaN    行业  全球瞪羚数量占比 NaN  NaN    行业  全球独角兽数量占比 NaN  NaN     行业  世界500强数量占比\n",
       " 1  1.0  医疗健康       23% NaN  1.0  金融服务        18% NaN  1.0   金融服务         19%\n",
       " 2  2.0  金融服务       18% NaN  2.0  企业管理        17% NaN  2.0   医疗健康         12%\n",
       " 3  3.0  企业管理       17% NaN  3.0  医疗健康        10% NaN  3.0     能源        7.4%\n",
       " 4  4.0    零售        5% NaN  4.0    零售         9% NaN  4.0  软件与服务        7.2%\n",
       " 5  5.0    物流        3% NaN  5.0  网络安全         5% NaN  5.0     零售          6%,\n",
       "           0        1       2    3    4\n",
       " 0       NaN  销售软件和服务  销售实体产品  B2B  B2C\n",
       " 1    全球瞪羚企业      74%     26%  58%  42%\n",
       " 2   全球独角兽企业      80%     20%  52%  48%\n",
       " 3  世界500强企业      46%     54%  44%  56%,\n",
       "      0   1            2   3     4    5            6   7     8    9   \\\n",
       " 0   NaN  城市  中国猎豹数量占全国比例 NaN   NaN   城市  中国瞪羚数量占全国比例 NaN   NaN   城市   \n",
       " 1   1.0  上海          22% NaN   1.0   上海          31% NaN   1.0   北京   \n",
       " 2   2.0  北京          20% NaN   2.0   北京          22% NaN   2.0   上海   \n",
       " 3   3.0  深圳          12% NaN   3.0   深圳          14% NaN   3.0   深圳   \n",
       " 4   3.0  杭州          12% NaN   4.0   杭州           9% NaN   4.0   杭州   \n",
       " 5   5.0  苏州         6.2% NaN   5.0   苏州           6% NaN   5.0   广州   \n",
       " 6   6.0  广州         5.8% NaN   6.0   广州           3% NaN   6.0   成都   \n",
       " 7   7.0  南京           4% NaN   6.0   南京           3% NaN   7.0   苏州   \n",
       " 8   8.0  厦门           2% NaN   8.0   武汉           2% NaN   7.0   南京   \n",
       " 9   9.0  成都           1% NaN   8.0   天津           2% NaN   7.0   香港   \n",
       " 10  9.0  嘉兴           1% NaN  10.0   珠海         1.5% NaN  10.0   青岛   \n",
       " 11  9.0  香港           1% NaN   NaN  NaN          NaN NaN   NaN  NaN   \n",
       " \n",
       "               10  11    12  13             14  \n",
       " 0   中国独角兽数量占全国比例 NaN   NaN  城市  中国500强数量占全国比例  \n",
       " 1            29% NaN   1.0  上海          13.7%  \n",
       " 2            22% NaN   2.0  北京          13.5%  \n",
       " 3            11% NaN   3.0  深圳             9%  \n",
       " 4             7% NaN   4.0  杭州             6%  \n",
       " 5             6% NaN   4.0  香港             6%  \n",
       " 6             3% NaN   6.0  台北             5%  \n",
       " 7             2% NaN   7.0  广州           3.2%  \n",
       " 8             2% NaN   8.0  苏州           2.6%  \n",
       " 9             2% NaN   9.0  宁波             2%  \n",
       " 10            2% NaN  10.0  长沙           1.8%  \n",
       " 11           NaN NaN  10.0  无锡           1.8%  ,\n",
       "     0     1            2   3    4     5            6   7    8     9   \\\n",
       " 0  NaN    行业  中国猎豹数量占全国比例 NaN  NaN    行业  中国瞪羚数量占全国比例 NaN  NaN    行业   \n",
       " 1  1.0  生命科学          23% NaN  1.0  医疗健康          34% NaN  1.0    零售   \n",
       " 2  2.0  医疗健康          12% NaN  2.0  企业管理          13% NaN  2.0  医疗健康   \n",
       " 3  3.0    零售           8% NaN  3.0   半导体           8% NaN  3.0   半导体   \n",
       " 4  4.0  消费电子         5.4% NaN  4.0    零售           6% NaN  4.0    物流   \n",
       " 5  5.0  企业管理         4.6% NaN  4.0  传媒娱乐           6% NaN  4.0    运输   \n",
       " 6  5.0    汽车         4.6% NaN  NaN   NaN          NaN NaN  NaN   NaN   \n",
       " 7  5.0  智能芯片         4.6% NaN  NaN   NaN          NaN NaN  NaN   NaN   \n",
       " \n",
       "              10  11   12    13             14  \n",
       " 0  中国独角兽数量占全国比例 NaN  NaN    行业  中国500强数量占全国比例  \n",
       " 1           11% NaN  1.0  医疗健康            14%  \n",
       " 2           10% NaN  2.0    能源             9%  \n",
       " 3            9% NaN  3.0    化工             8%  \n",
       " 4            6% NaN  4.0  电子元件           6.3%  \n",
       " 5            6% NaN  5.0    零售           6.2%  \n",
       " 6           NaN NaN  NaN   NaN            NaN  \n",
       " 7           NaN NaN  NaN   NaN            NaN  ,\n",
       "           0        1       2    3    4\n",
       " 0       NaN  销售软件和服务  销售实体产品  B2B  B2C\n",
       " 1    中国猎豹企业      53%     47%  71%  29%\n",
       " 2    中国瞪羚企业      47%     53%  69%  31%\n",
       " 3   中国独角兽企业      60%     40%  52%  48%\n",
       " 4  中国500强企业      23%     77%  56%  44%,\n",
       "         0      1    2       3      4       5                  6\n",
       " 0      年份  独角兽数量  新上榜  升级退出榜单  其中，上市  其中，被并购  降级退出榜单，即估值跌破10亿美元\n",
       " 1    2019    494    -       -      -       -                  -\n",
       " 2    2020    586  142      30     19      11                 20\n",
       " 3    2021   1058  673     162    137      25                 39\n",
       " 4  2022年中   1312  369      34     25       9                 81,\n",
       "                                                    0  \\\n",
       " 0  潘小英（Porsha Pan） 胡润百富 传讯副总监 电话：021-50105808 手机：...   \n",
       " \n",
       "                                                    1  \n",
       " 0  常婷（Larina Chang） 胡润百富 公关主任 电话：021-50105808 手机：...  ,\n",
       "       0     1                    2          3            4   5      6     7\n",
       " 0    排名  排名变化                 企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家     城市    行业\n",
       " 1     1     0                   抖音      13400       -10050  中国     北京  社交媒体\n",
       " 2     2     1               SpaceX       8400         1680  美国    洛杉矶    航天\n",
       " 3     3    -1                 蚂蚁集团       8000        -2010  中国     杭州  金融科技\n",
       " 4     4     0               Stripe       4100        -2210  美国    旧金山  金融科技\n",
       " ..   ..   ...                  ...        ...          ...  ..    ...   ...\n",
       " 97   95   -16        Impossible 食品        470            0  美国  雷德伍德城  食品饮料\n",
       " 98   95   -16                   微医        470            0  中国     杭州  健康科技\n",
       " 99   99    58                 蜂巢能源        460          190  中国     常州   新能源\n",
       " 100  99    -6           Better.com        460           60  美国     纽约  金融科技\n",
       " 101  99   -20  Automation Anywhere        460          -10  美国    圣何塞  人工智能\n",
       " \n",
       " [102 rows x 8 columns],\n",
       "        0     1                         2                         3  \\\n",
       " 0     排名  排名变化                      投资机构                  Investor   \n",
       " 1      1     0                      红杉资本           Sequoia Capital   \n",
       " 2      2     1                        软银                  SoftBank   \n",
       " 3      3    -1                    老虎环球基金                     Tiger   \n",
       " 4      4     4                        腾讯                   Tencent   \n",
       " ..   ...   ...                       ...                       ...   \n",
       " 104  100   -11  Durable Capital Partners  Durable Capital Partners   \n",
       " 105  100    -6                   Atomico                   Atomico   \n",
       " 106  100   New                    AME云创投        AME Cloud Ventures   \n",
       " 107  100   New             QED Investors             QED Investors   \n",
       " 108  100    -6                      门罗风投            Menlo Ventures   \n",
       " \n",
       "                4            5     6  \n",
       " 0    2022上榜独角兽数量  2021上榜独角兽数量  创立国家  \n",
       " 1            234          206    美国  \n",
       " 2            180          146    日本  \n",
       " 3            169          147    美国  \n",
       " 4             90           68    中国  \n",
       " ..           ...          ...   ...  \n",
       " 104           17           15    美国  \n",
       " 105           17           14    英国  \n",
       " 106           17           13    美国  \n",
       " 107           17           13    美国  \n",
       " 108           17           14    美国  \n",
       " \n",
       " [109 rows x 7 columns],\n",
       "        0                           1          2      3            4      5\n",
       " 0    NaN                          企业  价值（亿元人民币）     国家           城市     行业\n",
       " 1    1.0                          币安       3000    马耳他          马耳他    区块链\n",
       " 2    2.0          Citadel Securities       1500     美国          芝加哥   金融科技\n",
       " 3    3.0                        极兔速递       1300  印度尼西亚          雅加达   电子商务\n",
       " 4    3.0                          极星       1300     瑞典          哥德堡  新能源汽车\n",
       " 5    5.0                      Notion        670     美国          旧金山   软件服务\n",
       " 6    6.0                    Airtable        600     美国          旧金山   软件服务\n",
       " 7    7.0                        Nuro        575     美国          旧金山    机器人\n",
       " 8    8.0                    Scale AI        490     美国          旧金山   人工智能\n",
       " 9    9.0                        Weee        270     美国          菲蒙市   电子商务\n",
       " 10  10.0                    Workrise        190     美国          奥斯汀   电子商务\n",
       " 11  11.0                  Binance.US        185     美国          旧金山    区块链\n",
       " 12  12.0                        Lime        155     美国         圣马特奥   共享经济\n",
       " 13  13.0                   Moveworks        140     美国          山景城   人工智能\n",
       " 14  14.0                       Avant        135     美国          芝加哥   金融科技\n",
       " 15  14.0                 Sourcegraph        135     美国          旧金山   软件服务\n",
       " 16  16.0             Thatgamecompany        130     美国        圣塔莫尼卡     游戏\n",
       " 17  17.0                    Optimism        110     美国          旧金山    区块链\n",
       " 18  18.0                        Hive        100     美国          旧金山   软件服务\n",
       " 19  18.0                    Iterable        100     美国          旧金山   软件服务\n",
       " 20  20.0                        OPay         95   尼日利亚          伊凯贾   金融科技\n",
       " 21  21.0                 CaptivateIQ         80     美国          旧金山   软件服务\n",
       " 22  21.0                  GrubMarket         80     美国          旧金山     快递\n",
       " 23  23.0  Advance Intelligence Group         67    新加坡          新加坡   金融科技\n",
       " 24  23.0                Agile Robots         67     德国          吉尔兴    机器人\n",
       " 25  23.0                     EcoFlow         67     美国          旧金山    新能源\n",
       " 26  23.0               Flash Express         67     泰国           曼谷     物流\n",
       " 27  23.0                GetYourGuide         67     德国           柏林   电子商务\n",
       " 28  23.0              Human Interest         67     美国          旧金山   金融科技\n",
       " 29  23.0                  JupiterOne         67     美国  Morrisville   网络安全\n",
       " 30  23.0                  News Break         67     美国          山景城     传媒]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 这里所搜寻到的网页信息必须包含表格数据才能够被爬取\n",
    "hurun_独角兽 = pd.read_html('https://www.hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')\n",
    "hurun_独角兽\n",
    "# 这里输出的是 胡润网的表格数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "968f30a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(hurun_独角兽)\n",
    "# 这里输出的是数据列表的长度，可以通过逗号来计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5752a880",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>排名</td>\n",
       "      <td>排名变化</td>\n",
       "      <td>企业名称</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值变化（亿元人民币）</td>\n",
       "      <td>国家</td>\n",
       "      <td>城市</td>\n",
       "      <td>行业</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>SpaceX</td>\n",
       "      <td>8400</td>\n",
       "      <td>1680</td>\n",
       "      <td>美国</td>\n",
       "      <td>洛杉矶</td>\n",
       "      <td>航天</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>蚂蚁集团</td>\n",
       "      <td>8000</td>\n",
       "      <td>-2010</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>Stripe</td>\n",
       "      <td>4100</td>\n",
       "      <td>-2210</td>\n",
       "      <td>美国</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>Impossible 食品</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>美国</td>\n",
       "      <td>雷德伍德城</td>\n",
       "      <td>食品饮料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>微医</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>健康科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>蜂巢能源</td>\n",
       "      <td>460</td>\n",
       "      <td>190</td>\n",
       "      <td>中国</td>\n",
       "      <td>常州</td>\n",
       "      <td>新能源</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>99</td>\n",
       "      <td>-6</td>\n",
       "      <td>Better.com</td>\n",
       "      <td>460</td>\n",
       "      <td>60</td>\n",
       "      <td>美国</td>\n",
       "      <td>纽约</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>99</td>\n",
       "      <td>-20</td>\n",
       "      <td>Automation Anywhere</td>\n",
       "      <td>460</td>\n",
       "      <td>-10</td>\n",
       "      <td>美国</td>\n",
       "      <td>圣何塞</td>\n",
       "      <td>人工智能</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>102 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      0     1                    2          3            4   5      6     7\n",
       "0    排名  排名变化                 企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家     城市    行业\n",
       "1     1     0                   抖音      13400       -10050  中国     北京  社交媒体\n",
       "2     2     1               SpaceX       8400         1680  美国    洛杉矶    航天\n",
       "3     3    -1                 蚂蚁集团       8000        -2010  中国     杭州  金融科技\n",
       "4     4     0               Stripe       4100        -2210  美国    旧金山  金融科技\n",
       "..   ..   ...                  ...        ...          ...  ..    ...   ...\n",
       "97   95   -16        Impossible 食品        470            0  美国  雷德伍德城  食品饮料\n",
       "98   95   -16                   微医        470            0  中国     杭州  健康科技\n",
       "99   99    58                 蜂巢能源        460          190  中国     常州   新能源\n",
       "100  99    -6           Better.com        460           60  美国     纽约  金融科技\n",
       "101  99   -20  Automation Anywhere        460          -10  美国    圣何塞  人工智能\n",
       "\n",
       "[102 rows x 8 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = hurun_独角兽[-3]\n",
    "df\n",
    "# 这里是取 hurun_独角兽 列表中的 倒数第三个数据列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3e7c05e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>排名</td>\n",
       "      <td>排名变化</td>\n",
       "      <td>企业名称</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值变化（亿元人民币）</td>\n",
       "      <td>国家</td>\n",
       "      <td>城市</td>\n",
       "      <td>行业</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    0     1     2          3            4   5   6   7\n",
       "0  排名  排名变化  企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家  城市  行业"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 这个是没替换表头前的样式\n",
    "df[0:1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05eb2ee5",
   "metadata": {},
   "source": [
    "### Q: 如何将列表的 第一行 按照 排名 排名变化 企业名称 价值 价值变化 国家 城市 行业 这个顺序进行排列？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "770f486e",
   "metadata": {},
   "source": [
    "> 1. 先用列表取值的方法取出第一行的所有值，如果是 df[0] 则是列表第一列的所有值，而 df[0:1] 则是列表第一行的所所有值\n",
    "> * 所以 为了取出 列表的 第一列 第一步要进行的操作是 df[0:1]\n",
    "> 2. 在 pandas 中 pd.values 其 values 属性 对应的是 二维NumPy值数组\n",
    "> * 所以 为了将 二维的数据列表 转成 计算机 所能够进行操作的值 第二步要进行的操作是 df[0:1].values\n",
    "> 3. 在 Pandas 中 为了将 DataFrame 转换成 list 需要用到 tolist \n",
    "> * 详情请看[这里](https://blog.csdn.net/sinat_26811377/article/details/99292830)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "706278fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['排名', '排名变化', '企业名称', '价值（亿元人民币）', '价值变化（亿元人民币）', '国家', '城市', '行业']]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[0:1].values.tolist()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "221241fa",
   "metadata": {},
   "source": [
    "> 4. 在 pandas 中 pd.columns 其 columns 属性 对应的是 列索引：列名称（也可以说成是表头所在）\n",
    "> * 所以可以利用 这个属性 将其表头进行替换 替换后的表格样式如下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "cf0fab48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>排名</th>\n",
       "      <th>排名变化</th>\n",
       "      <th>企业名称</th>\n",
       "      <th>价值（亿元人民币）</th>\n",
       "      <th>价值变化（亿元人民币）</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>行业</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>排名</td>\n",
       "      <td>排名变化</td>\n",
       "      <td>企业名称</td>\n",
       "      <td>价值（亿元人民币）</td>\n",
       "      <td>价值变化（亿元人民币）</td>\n",
       "      <td>国家</td>\n",
       "      <td>城市</td>\n",
       "      <td>行业</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   排名  排名变化  企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家  城市  行业\n",
       "0  排名  排名变化  企业名称  价值（亿元人民币）  价值变化（亿元人民币）  国家  城市  行业"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns = df[0:1].values.tolist()[0]\n",
    "# 这个是替换了表头后的样式\n",
    "df[0:1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "301c83db",
   "metadata": {},
   "source": [
    "##### 从上图能明显看出 表头 和 数据表格的第一行 有所冲突 所以 对表格的第一行进行删除\n",
    "##### [具体](https://blog.csdn.net/qq_18351157/article/details/105785367)删除方法\n",
    "* 利用参数索引 删除 索引值为 0 的那一行\n",
    "    * 即 df.drop(index=[0]) == df.drop([0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "1f96ae52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>排名</th>\n",
       "      <th>排名变化</th>\n",
       "      <th>企业名称</th>\n",
       "      <th>价值（亿元人民币）</th>\n",
       "      <th>价值变化（亿元人民币）</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>行业</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  排名 排名变化 企业名称 价值（亿元人民币） 价值变化（亿元人民币）  国家  城市    行业\n",
       "1  1    0   抖音     13400      -10050  中国  北京  社交媒体"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.drop([0])\n",
    "df[0:1]\n",
    "# 下图便是删除后的变化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f98a3b5c",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>排名</th>\n",
       "      <th>排名变化</th>\n",
       "      <th>企业名称</th>\n",
       "      <th>价值（亿元人民币）</th>\n",
       "      <th>价值变化（亿元人民币）</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>行业</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>抖音</td>\n",
       "      <td>13400</td>\n",
       "      <td>-10050</td>\n",
       "      <td>中国</td>\n",
       "      <td>北京</td>\n",
       "      <td>社交媒体</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>SpaceX</td>\n",
       "      <td>8400</td>\n",
       "      <td>1680</td>\n",
       "      <td>美国</td>\n",
       "      <td>洛杉矶</td>\n",
       "      <td>航天</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>蚂蚁集团</td>\n",
       "      <td>8000</td>\n",
       "      <td>-2010</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>Stripe</td>\n",
       "      <td>4100</td>\n",
       "      <td>-2210</td>\n",
       "      <td>美国</td>\n",
       "      <td>旧金山</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "      <td>Shein</td>\n",
       "      <td>4000</td>\n",
       "      <td>2680</td>\n",
       "      <td>中国</td>\n",
       "      <td>广州</td>\n",
       "      <td>电子商务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>Impossible 食品</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>美国</td>\n",
       "      <td>雷德伍德城</td>\n",
       "      <td>食品饮料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>95</td>\n",
       "      <td>-16</td>\n",
       "      <td>微医</td>\n",
       "      <td>470</td>\n",
       "      <td>0</td>\n",
       "      <td>中国</td>\n",
       "      <td>杭州</td>\n",
       "      <td>健康科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>99</td>\n",
       "      <td>58</td>\n",
       "      <td>蜂巢能源</td>\n",
       "      <td>460</td>\n",
       "      <td>190</td>\n",
       "      <td>中国</td>\n",
       "      <td>常州</td>\n",
       "      <td>新能源</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>99</td>\n",
       "      <td>-6</td>\n",
       "      <td>Better.com</td>\n",
       "      <td>460</td>\n",
       "      <td>60</td>\n",
       "      <td>美国</td>\n",
       "      <td>纽约</td>\n",
       "      <td>金融科技</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>99</td>\n",
       "      <td>-20</td>\n",
       "      <td>Automation Anywhere</td>\n",
       "      <td>460</td>\n",
       "      <td>-10</td>\n",
       "      <td>美国</td>\n",
       "      <td>圣何塞</td>\n",
       "      <td>人工智能</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>101 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     排名 排名变化                 企业名称 价值（亿元人民币） 价值变化（亿元人民币）  国家     城市    行业\n",
       "1     1    0                   抖音     13400      -10050  中国     北京  社交媒体\n",
       "2     2    1               SpaceX      8400        1680  美国    洛杉矶    航天\n",
       "3     3   -1                 蚂蚁集团      8000       -2010  中国     杭州  金融科技\n",
       "4     4    0               Stripe      4100       -2210  美国    旧金山  金融科技\n",
       "5     5   11                Shein      4000        2680  中国     广州  电子商务\n",
       "..   ..  ...                  ...       ...         ...  ..    ...   ...\n",
       "97   95  -16        Impossible 食品       470           0  美国  雷德伍德城  食品饮料\n",
       "98   95  -16                   微医       470           0  中国     杭州  健康科技\n",
       "99   99   58                 蜂巢能源       460         190  中国     常州   新能源\n",
       "100  99   -6           Better.com       460          60  美国     纽约  金融科技\n",
       "101  99  -20  Automation Anywhere       460         -10  美国    圣何塞  人工智能\n",
       "\n",
       "[101 rows x 8 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 于是 就完成了我们的目标 成功将表格进行了修改\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3967eaa",
   "metadata": {},
   "source": [
    "## 二、 Dataframe.groupby\n",
    "\n",
    "* 参考文档1:[groupby](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html)\n",
    "* 参考文档2:[groupby](https://blog.csdn.net/qq_45186086/article/details/125237895)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce274a98",
   "metadata": {},
   "source": [
    "### Q: 如何将数据列表按照用户所需要的进行分类，例如按照 国家、企业名称 的 价值 或者 价值变化等 进行分类？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c66a0466",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将数据类型进行转换\n",
    "df['价值（亿元人民币）'] = df['价值（亿元人民币）'].astype('int32')\n",
    "df.排名 = df.排名.astype('int64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "9875a1bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "排名              int64\n",
       "排名变化           object\n",
       "企业名称           object\n",
       "价值（亿元人民币）       int32\n",
       "价值变化（亿元人民币）    object\n",
       "国家             object\n",
       "城市             object\n",
       "行业             object\n",
       "dtype: object"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "e87482cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "国家\n",
       "中国       42.730769\n",
       "以色列      75.000000\n",
       "印度       56.250000\n",
       "印度尼西亚    30.500000\n",
       "土耳其      36.000000\n",
       "墨西哥      62.000000\n",
       "巴哈马      16.000000\n",
       "德国       71.000000\n",
       "澳大利亚     12.000000\n",
       "瑞典       26.000000\n",
       "瑞士       65.000000\n",
       "美国       54.653061\n",
       "英国       47.857143\n",
       "越南       71.000000\n",
       "韩国       72.000000\n",
       "马耳他       6.000000\n",
       "Name: 排名, dtype: float64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 按照 国家 进行分组 并输出了 每个国家的 价值 的平均值 \n",
    "# mean(),sum(),count(),max(),min()都是聚合函数中的一种\n",
    "df_country = df.groupby('国家')['排名'].mean()\n",
    "df_country"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "2a8eb486",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"5\" halign=\"left\">价值（亿元人民币）</th>\n",
       "      <th colspan=\"2\" halign=\"left\">价值变化（亿元人民币）</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "      <th>sum</th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>国家</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>中国</th>\n",
       "      <td>13400</td>\n",
       "      <td>460</td>\n",
       "      <td>46055</td>\n",
       "      <td>26</td>\n",
       "      <td>1771.346154</td>\n",
       "      <td>New</td>\n",
       "      <td>-10050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>以色列</th>\n",
       "      <td>535</td>\n",
       "      <td>535</td>\n",
       "      <td>535</td>\n",
       "      <td>1</td>\n",
       "      <td>535.000000</td>\n",
       "      <td>400</td>\n",
       "      <td>400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>印度</th>\n",
       "      <td>1500</td>\n",
       "      <td>480</td>\n",
       "      <td>3235</td>\n",
       "      <td>4</td>\n",
       "      <td>808.750000</td>\n",
       "      <td>70</td>\n",
       "      <td>-160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>印度尼西亚</th>\n",
       "      <td>1300</td>\n",
       "      <td>700</td>\n",
       "      <td>2000</td>\n",
       "      <td>2</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>土耳其</th>\n",
       "      <td>800</td>\n",
       "      <td>800</td>\n",
       "      <td>800</td>\n",
       "      <td>1</td>\n",
       "      <td>800.000000</td>\n",
       "      <td>300</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>墨西哥</th>\n",
       "      <td>580</td>\n",
       "      <td>580</td>\n",
       "      <td>580</td>\n",
       "      <td>1</td>\n",
       "      <td>580.000000</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>巴哈马</th>\n",
       "      <td>1300</td>\n",
       "      <td>1300</td>\n",
       "      <td>1300</td>\n",
       "      <td>1</td>\n",
       "      <td>1300.000000</td>\n",
       "      <td>-340</td>\n",
       "      <td>-340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>德国</th>\n",
       "      <td>555</td>\n",
       "      <td>555</td>\n",
       "      <td>555</td>\n",
       "      <td>1</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>-190</td>\n",
       "      <td>-190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>澳大利亚</th>\n",
       "      <td>1750</td>\n",
       "      <td>1750</td>\n",
       "      <td>1750</td>\n",
       "      <td>1</td>\n",
       "      <td>1750.000000</td>\n",
       "      <td>-940</td>\n",
       "      <td>-940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>瑞典</th>\n",
       "      <td>1300</td>\n",
       "      <td>800</td>\n",
       "      <td>2100</td>\n",
       "      <td>2</td>\n",
       "      <td>1050.000000</td>\n",
       "      <td>1010</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>瑞士</th>\n",
       "      <td>575</td>\n",
       "      <td>575</td>\n",
       "      <td>575</td>\n",
       "      <td>1</td>\n",
       "      <td>575.000000</td>\n",
       "      <td>-70</td>\n",
       "      <td>-70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>美国</th>\n",
       "      <td>8400</td>\n",
       "      <td>460</td>\n",
       "      <td>47740</td>\n",
       "      <td>49</td>\n",
       "      <td>974.285714</td>\n",
       "      <td>New</td>\n",
       "      <td>-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英国</th>\n",
       "      <td>1900</td>\n",
       "      <td>520</td>\n",
       "      <td>6575</td>\n",
       "      <td>7</td>\n",
       "      <td>939.285714</td>\n",
       "      <td>870</td>\n",
       "      <td>-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>越南</th>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>1</td>\n",
       "      <td>550.000000</td>\n",
       "      <td>New</td>\n",
       "      <td>New</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>韩国</th>\n",
       "      <td>560</td>\n",
       "      <td>535</td>\n",
       "      <td>1095</td>\n",
       "      <td>2</td>\n",
       "      <td>547.500000</td>\n",
       "      <td>New</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>马耳他</th>\n",
       "      <td>3000</td>\n",
       "      <td>3000</td>\n",
       "      <td>3000</td>\n",
       "      <td>1</td>\n",
       "      <td>3000.000000</td>\n",
       "      <td>2010</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      价值（亿元人民币）                                 价值变化（亿元人民币）        \n",
       "            max   min    sum count         mean         max     min\n",
       "国家                                                                 \n",
       "中国        13400   460  46055    26  1771.346154         New  -10050\n",
       "以色列         535   535    535     1   535.000000         400     400\n",
       "印度         1500   480   3235     4   808.750000          70    -160\n",
       "印度尼西亚      1300   700   2000     2  1000.000000           0       0\n",
       "土耳其         800   800    800     1   800.000000         300     300\n",
       "墨西哥         580   580    580     1   580.000000          10      10\n",
       "巴哈马        1300  1300   1300     1  1300.000000        -340    -340\n",
       "德国          555   555    555     1   555.000000        -190    -190\n",
       "澳大利亚       1750  1750   1750     1  1750.000000        -940    -940\n",
       "瑞典         1300   800   2100     2  1050.000000        1010       0\n",
       "瑞士          575   575    575     1   575.000000         -70     -70\n",
       "美国         8400   460  47740    49   974.285714         New     -10\n",
       "英国         1900   520   6575     7   939.285714         870     -10\n",
       "越南          550   550    550     1   550.000000         New     New\n",
       "韩国          560   535   1095     2   547.500000         New     500\n",
       "马耳他        3000  3000   3000     1  3000.000000        2010    2010"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 一、按照国家进行分类，并打印出每个国家所对应的 价值和价值变化 的最大最小值 和 总值，其中 出现的 NEW 是表格本身的数据类型出现问题\n",
    "# 无法转换成数值型\n",
    "# 而 agg 能把这些聚合函数进行统一\n",
    "df_国家 = df.groupby(by=['国家']).agg({'价值（亿元人民币）':['max','min','sum','count','mean'],'价值变化（亿元人民币）':['max','min']})\n",
    "df_国家"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "59eaacc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"4\" halign=\"left\">价值（亿元人民币）</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>max</th>\n",
       "      <th>min</th>\n",
       "      <th>sum</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>行业</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>人工智能</th>\n",
       "      <td>870</td>\n",
       "      <td>460</td>\n",
       "      <td>3560</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>企业服务</th>\n",
       "      <td>1170</td>\n",
       "      <td>515</td>\n",
       "      <td>1685</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>保险</th>\n",
       "      <td>740</td>\n",
       "      <td>740</td>\n",
       "      <td>740</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>健康科技</th>\n",
       "      <td>1040</td>\n",
       "      <td>470</td>\n",
       "      <td>2820</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>共享经济</th>\n",
       "      <td>1000</td>\n",
       "      <td>480</td>\n",
       "      <td>3145</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>分析</th>\n",
       "      <td>575</td>\n",
       "      <td>575</td>\n",
       "      <td>575</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>区块链</th>\n",
       "      <td>3000</td>\n",
       "      <td>500</td>\n",
       "      <td>8615</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>大数据</th>\n",
       "      <td>2500</td>\n",
       "      <td>535</td>\n",
       "      <td>3035</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>快递</th>\n",
       "      <td>1320</td>\n",
       "      <td>720</td>\n",
       "      <td>3840</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>教育科技</th>\n",
       "      <td>1500</td>\n",
       "      <td>1500</td>\n",
       "      <td>1500</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数字科技</th>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新能源</th>\n",
       "      <td>800</td>\n",
       "      <td>460</td>\n",
       "      <td>2570</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新能源汽车</th>\n",
       "      <td>1300</td>\n",
       "      <td>600</td>\n",
       "      <td>1900</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新零售</th>\n",
       "      <td>670</td>\n",
       "      <td>670</td>\n",
       "      <td>670</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>机器人</th>\n",
       "      <td>1200</td>\n",
       "      <td>575</td>\n",
       "      <td>1775</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>消费品</th>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>550</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>游戏</th>\n",
       "      <td>600</td>\n",
       "      <td>535</td>\n",
       "      <td>1135</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>物流</th>\n",
       "      <td>1800</td>\n",
       "      <td>500</td>\n",
       "      <td>4905</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>生物科技</th>\n",
       "      <td>800</td>\n",
       "      <td>540</td>\n",
       "      <td>1340</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>电子商务</th>\n",
       "      <td>4000</td>\n",
       "      <td>490</td>\n",
       "      <td>9110</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>社交媒体</th>\n",
       "      <td>13400</td>\n",
       "      <td>1000</td>\n",
       "      <td>14400</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>网络安全</th>\n",
       "      <td>600</td>\n",
       "      <td>535</td>\n",
       "      <td>1690</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>航天</th>\n",
       "      <td>8400</td>\n",
       "      <td>8400</td>\n",
       "      <td>8400</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>软件服务</th>\n",
       "      <td>1750</td>\n",
       "      <td>470</td>\n",
       "      <td>9695</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>金融科技</th>\n",
       "      <td>8000</td>\n",
       "      <td>460</td>\n",
       "      <td>27320</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>食品饮料</th>\n",
       "      <td>1000</td>\n",
       "      <td>470</td>\n",
       "      <td>1470</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      价值（亿元人民币）                   \n",
       "            max   min    sum count\n",
       "行业                                \n",
       "人工智能        870   460   3560     6\n",
       "企业服务       1170   515   1685     2\n",
       "保险          740   740    740     1\n",
       "健康科技       1040   470   2820     4\n",
       "共享经济       1000   480   3145     4\n",
       "分析          575   575    575     1\n",
       "区块链        3000   500   8615     9\n",
       "大数据        2500   535   3035     2\n",
       "快递         1320   720   3840     4\n",
       "教育科技       1500  1500   1500     1\n",
       "数字科技       2000  2000   2000     1\n",
       "新能源         800   460   2570     4\n",
       "新能源汽车      1300   600   1900     2\n",
       "新零售         670   670    670     1\n",
       "机器人        1200   575   1775     2\n",
       "消费品         550   550    550     1\n",
       "游戏          600   535   1135     2\n",
       "物流         1800   500   4905     5\n",
       "生物科技        800   540   1340     2\n",
       "电子商务       4000   490   9110     8\n",
       "社交媒体      13400  1000  14400     2\n",
       "网络安全        600   535   1690     3\n",
       "航天         8400  8400   8400     1\n",
       "软件服务       1750   470   9695    14\n",
       "金融科技       8000   460  27320    17\n",
       "食品饮料       1000   470   1470     2"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 二、按照 行业 进行分类，并打印出每个行业所对应的 价值 的最大最小值 和 总值\n",
    "df_行业 = df.groupby(by=['行业']).agg({'价值（亿元人民币）':['max','min','sum','count']})\n",
    "df_行业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3123d98",
   "metadata": {},
   "source": [
    "## 三、Dataframe.to_excel()\n",
    "\n",
    "* 参考文档1：[Dataframe.to_excel](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html)\n",
    "* 参考文档2:[Dataframe.to_excel](https://www.cnblogs.com/meitian/p/10466198.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "15c68270",
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.ExcelWriter('胡润独角兽排行榜整理.xlsx') as writer: \n",
    "    df_国家.to_excel(writer, sheet_name='国家汇总')\n",
    "    df_行业.to_excel(writer, sheet_name='行业汇总')\n",
    "    \n",
    "# 通过生成的excel表格 易知 生成了两个新表格 也就是 sheet1 和 sheet2 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b570b9a",
   "metadata": {},
   "source": [
    "# 体验项目二\n",
    "\n",
    "* 核心模块：requests-html [参考文档](https://requests.readthedocs.io/projects/requests-html/en/latest/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ea45fed5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Requirement already satisfied: requests-html in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (0.10.0)\n",
      "Requirement already satisfied: pyquery in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from requests-html) (2.0.0)\n",
      "Requirement already satisfied: fake-useragent in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from requests-html) (1.1.1)\n",
      "Requirement already satisfied: bs4 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from requests-html) (0.0.1)\n",
      "Requirement already satisfied: pyppeteer>=0.0.14 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from requests-html) (1.0.2)\n",
      "Requirement already satisfied: parse in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from requests-html) (1.19.0)\n",
      "Requirement already satisfied: w3lib in d:\\anaconda\\lib\\site-packages (from requests-html) (1.21.0)\n",
      "Requirement already satisfied: requests in d:\\anaconda\\lib\\site-packages (from requests-html) (2.28.1)\n",
      "Requirement already satisfied: importlib-metadata>=1.4 in d:\\anaconda\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (4.11.3)\n",
      "Requirement already satisfied: certifi>=2021 in d:\\anaconda\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (2022.9.14)\n",
      "Requirement already satisfied: pyee<9.0.0,>=8.1.0 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from pyppeteer>=0.0.14->requests-html) (8.2.2)\n",
      "Requirement already satisfied: appdirs<2.0.0,>=1.4.3 in d:\\anaconda\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.4.4)\n",
      "Requirement already satisfied: tqdm<5.0.0,>=4.42.1 in d:\\anaconda\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (4.64.1)\n",
      "Requirement already satisfied: websockets<11.0,>=10.0 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from pyppeteer>=0.0.14->requests-html) (10.4)\n",
      "Requirement already satisfied: urllib3<2.0.0,>=1.25.8 in d:\\anaconda\\lib\\site-packages (from pyppeteer>=0.0.14->requests-html) (1.26.11)\n",
      "Requirement already satisfied: beautifulsoup4 in d:\\anaconda\\lib\\site-packages (from bs4->requests-html) (4.11.1)\n",
      "Requirement already satisfied: importlib-resources>=5.0 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from fake-useragent->requests-html) (5.12.0)\n",
      "Requirement already satisfied: cssselect>=1.2.0 in c:\\users\\10735\\appdata\\roaming\\python\\python39\\site-packages (from pyquery->requests-html) (1.2.0)\n",
      "Requirement already satisfied: lxml>=2.1 in d:\\anaconda\\lib\\site-packages (from pyquery->requests-html) (4.9.1)\n",
      "Requirement already satisfied: charset-normalizer<3,>=2 in d:\\anaconda\\lib\\site-packages (from requests->requests-html) (2.0.4)\n",
      "Requirement already satisfied: idna<4,>=2.5 in d:\\anaconda\\lib\\site-packages (from requests->requests-html) (3.3)\n",
      "Requirement already satisfied: six>=1.4.1 in d:\\anaconda\\lib\\site-packages (from w3lib->requests-html) (1.16.0)\n",
      "Requirement already satisfied: zipp>=0.5 in d:\\anaconda\\lib\\site-packages (from importlib-metadata>=1.4->pyppeteer>=0.0.14->requests-html) (3.8.0)\n",
      "Requirement already satisfied: colorama in d:\\anaconda\\lib\\site-packages (from tqdm<5.0.0,>=4.42.1->pyppeteer>=0.0.14->requests-html) (0.4.5)\n",
      "Requirement already satisfied: soupsieve>1.2 in d:\\anaconda\\lib\\site-packages (from beautifulsoup4->bs4->requests-html) (2.3.1)\n"
     ]
    }
   ],
   "source": [
    "# 首先安装这个 requests-html 模块\n",
    "!pip install requests-html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0fac6888",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from requests_html import HTMLSession\n",
    "session = HTMLSession()\n",
    "# 这里爬取的是 广州南方学院 的官网\n",
    "r = session.get('https://www.nfu.edu.cn/')\n",
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fdcc5b7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'jycg/86044217245445f084c421ea6c300f2e.htm', 'https://www.nfu.edu.cn/xxyw/dba38546c79643549ec79bf7422b49bd.htm', 'rczp/glxl/index.htm', 'http://www.moe.gov.cn/', 'jycg/af424c1ed4d74e78b43e546b457d5ae9.htm', 'http://ky.nfu.edu.cn/', 'xsjz/9d503e8889cb4121a19a6825bdaa25e7.htm', 'jycg/c9b2de8b3ca140398639295ada9f3f33.htm', 'xydt/index.htm', 'jycg/79f5045bbe6d4c96a70f70a75327539a.htm', 'gjdt/index.htm', 'http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011702000081', 'rcpy/msjs/index.htm', 'http://gj.nfu.edu.cn/Home/Waishi/waishilist/class/1/p/1.html', 'jycg/e31a222779844699bb775f6e90b9a61e.htm', 'gjdt/c0546f17d79346a8b0526332862ac2f9.htm', 'http://xy.nfu.edu.cn/', 'jxky/index.htm', 'dshyx/index.htm', 'https://beian.miit.gov.cn/', 'http://www.nfu.edu.cn/xxgk/xxxl/index.htm', 'tzgg/4c55321c217b4e4587c30b816ec1d40a.htm', 'ztb/3e672d87f8544a11930a436c11fdb4fe.htm', 'jgsz/index.htm', 'mtnf/index.htm', 'xxyw/index.htm', 'ztb/54771dd76b934f0b8c31cdf84ab5af46.htm', 'http://service.nfu.edu.cn', 'http://cpc.nfu.edu.cn/', 'xxyw/c0b256a57c144bd3954ba7cbeff4efa3.htm', 'tzgg/5cc90b5a23cd42679746904a1de47a10.htm', 'xydt/210ae5d6a404496aa6600a7f195441c8.htm', 'jycg/df569615ee314b188d50d7277f414762.htm', 'http://www.gz.gov.cn/', 'gjdt/840b1bbfaa76444e8647dcb5d2824722.htm', 'http://jx.nfu.edu.cn/', 'rczp/jsxl/index.htm', 'tzgg/894ac62a1d06411abada0b3de37866ba.htm', 'jycg/cc9fb843b6ff442ab911c97585ed070d.htm', 'tzgg/cf024e1fb49042ed9af7612e47f525ef.htm', 'tzgg/index.htm', 'xxgk/xhxxxg/index.htm', 'xxgk/index.htm', 'http://jw.nfu.edu.cn/', 'gjdt/b522e143076746e1a82e017f6948846f.htm', 'xydt/2c3ae9a90a9d44ecbc8dd090ddf4c7fc.htm', 'https://www.nfu.edu.cn/xxyw/5d72606cd9244be2aaf87e33fadbdcdd.htm', 'ztb/e9fc641fc5d347028808b3ba47ec099f.htm', 'mtnf/707537b9681e4d3bbe52104b77f4a01b.htm', 'http://lib.nfu.edu.cn/', 'xs/index.htm', 'tsg/index.htm', 'jycg/b2fab55d3c984891bd5243553e5098b0.htm', 'mtnf/50233f981b3840689c8b386f2d590828.htm', 'jgsz/yxsz/index.htm', 'https://www.nfu.edu.cn/', 'xcyx/index.htm', 'xxgk/xxjj/index.htm', 'mtnf/65773dceec8a4056a0cceb8e986580e4.htm', 'mtnf/92d4562302334422b7c21083b5301610.htm', 'xydt/9097b8c486d249beb27a85d23d057510.htm', 'http://www.sysu.edu.cn/2012/cn/index.htm', 'ztb/b9065d0931004817bc95d98dbd54d732.htm', 'http://gj.nfu.edu.cn/', 'ztb/75a2c1db585b41278df8540181ce6fd5.htm', 'https://www.nfu.edu.cn/xxyw/90841c3eebff41a499c7adf3c9471692.htm', 'xsjz/index.htm', 'jycg/15b4a2a97b6e4cb08af99b3608e006ed.htm', 'jycg/3e91076c0c1f441aaa1ff6d407ea47b2.htm', 'tzgg/de405112880f4acaa92c18da7d23af7e.htm', 'jycg/a32d76179fba4d788a32d152c28b055c.htm', 'http://www.gdmbjy.cn/', 'ztb/4a9e537abfac499fa779e1711fcf6444.htm', 'https://ershida.nfu.edu.cn/', 'xinxi/index.htm', 'tzgg/d0a8a96d1cb448d6a3bc8057ec7e1638.htm', 'tzgg/9108102fc61d45d196e9eb23138d67aa.htm', 'zsjy/index.htm', 'https://www.nfu.edu.cn/xxyw/415d61fa1f9f41e29fd7ee35e64acf36.htm', 'rcpy/index.htm', 'http://zsb.nfu.edu.cn/', 'zjnf/index.htm', 'zsjy/jyfw/index.htm', 'zjnf/xb/index.htm', 'http://das.nfu.edu.cn/', 'jgsz/gljg/index.htm', 'xxyw/993b76be5b714ca4b5de8acf95835c81.htm', 'jycg/7b7d0e44d0224114bad71da804427001.htm', 'jycg/a515ee51daa04ffd8d208a144d784f87.htm', 'xsjz/4d01c24d7d6446788b72363adb833a4e.htm', 'ztb/index.htm', 'tzgg/6e3ca3ee8a4c4ae38a49ea806f017fa8.htm', 'http://edu.gd.gov.cn/', 'xxgk/xrld/index.htm', 'yxnf1/yxnf/index.htm', 'hzjl/index.htm', 'jgsz/cswyh/index.htm', 'http://en.nfu.edu.cn/', 'ztb/480fcc5e74114fbeb6ba749819464f22.htm', 'xxyw/60bb79f3c6e645fb8c804b6e1a6f3c35.htm', 'jycg/e2234c554b4a4546aa6efffd6d42531f.htm', 'https://www.gpowersoft.com/', 'tzgg/fe70fb0a36e84c9d9d997c7ed302f882.htm', 'xxgk/xxxl/index.htm', 'xxgk/nfdsj/index.htm', 'index.htm', 'zjnf/shfw/index.htm', 'zjnf/tsnf/index.htm', 'jycg/244313b7e85542fe86963b07d1a348c0.htm', 'http://www.gdpr.com/', 'https://www.cnki.net/', 'ztb/b983ab5b8a07419988a8642b29a0e26a.htm', 'tzgg/c303f270e52346a19df519507c746a0c.htm', 'ztb/dfeb908c5e9f42308efc09df7f8fd9c1.htm', 'jxky/kyjg/index.htm', 'rcpy/bkjy/index.htm', 'zjnf/ylfw/index.htm', 'rczp/index.htm', 'zjnf/jtzy/index.htm', 'xsjz/8271827d52f3445cb6ebaaae4ac50dcb.htm', 'jycg/0c29cbe53c1345c49707426b7db8ce6e.htm', 'ztb/095657e18243451eb90ed1a16d79d749.htm', 'rcpy/jxjy/index.htm', 'gjdt/a78b679c97004ee587a80bf789c241f1.htm'}\n"
     ]
    }
   ],
   "source": [
    "# 爬取广州南方学院官网首页的所有路径\n",
    "all_links =  r.html.links\n",
    "print(all_links)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5d6209c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'https://www.nfu.edu.cn/jgsz/index.htm', 'https://www.nfu.edu.cn/hzjl/index.htm', 'https://www.nfu.edu.cn/jycg/244313b7e85542fe86963b07d1a348c0.htm', 'https://www.nfu.edu.cn/xxyw/dba38546c79643549ec79bf7422b49bd.htm', 'https://www.nfu.edu.cn/gjdt/b522e143076746e1a82e017f6948846f.htm', 'https://www.nfu.edu.cn/jycg/b2fab55d3c984891bd5243553e5098b0.htm', 'https://www.nfu.edu.cn/mtnf/65773dceec8a4056a0cceb8e986580e4.htm', 'https://www.nfu.edu.cn/dshyx/index.htm', 'http://www.moe.gov.cn/', 'https://www.nfu.edu.cn/jycg/c9b2de8b3ca140398639295ada9f3f33.htm', 'https://www.nfu.edu.cn/xxgk/nfdsj/index.htm', 'https://www.nfu.edu.cn/jycg/af424c1ed4d74e78b43e546b457d5ae9.htm', 'https://www.nfu.edu.cn/xs/index.htm', 'http://ky.nfu.edu.cn/', 'https://www.nfu.edu.cn/jycg/0c29cbe53c1345c49707426b7db8ce6e.htm', 'https://www.nfu.edu.cn/xydt/index.htm', 'https://www.nfu.edu.cn/jycg/df569615ee314b188d50d7277f414762.htm', 'https://www.nfu.edu.cn/xxgk/index.htm', 'https://www.nfu.edu.cn/tzgg/c303f270e52346a19df519507c746a0c.htm', 'https://www.nfu.edu.cn/rcpy/index.htm', 'http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44011702000081', 'https://www.nfu.edu.cn/xsjz/8271827d52f3445cb6ebaaae4ac50dcb.htm', 'http://gj.nfu.edu.cn/Home/Waishi/waishilist/class/1/p/1.html', 'https://www.nfu.edu.cn/tzgg/5cc90b5a23cd42679746904a1de47a10.htm', 'http://xy.nfu.edu.cn/', 'https://beian.miit.gov.cn/', 'http://www.nfu.edu.cn/xxgk/xxxl/index.htm', 'https://www.nfu.edu.cn/xxgk/xxxl/index.htm', 'https://www.nfu.edu.cn/ztb/54771dd76b934f0b8c31cdf84ab5af46.htm', 'https://www.nfu.edu.cn/xxgk/xhxxxg/index.htm', 'https://www.nfu.edu.cn/jgsz/gljg/index.htm', 'https://www.nfu.edu.cn/jgsz/yxsz/index.htm', 'https://www.nfu.edu.cn/xcyx/index.htm', 'http://service.nfu.edu.cn', 'https://www.nfu.edu.cn/tzgg/d0a8a96d1cb448d6a3bc8057ec7e1638.htm', 'http://cpc.nfu.edu.cn/', 'http://www.gz.gov.cn/', 'https://www.nfu.edu.cn/rczp/glxl/index.htm', 'http://jx.nfu.edu.cn/', 'https://www.nfu.edu.cn/jycg/7b7d0e44d0224114bad71da804427001.htm', 'https://www.nfu.edu.cn/zsjy/jyfw/index.htm', 'https://www.nfu.edu.cn/jgsz/cswyh/index.htm', 'https://www.nfu.edu.cn/xxyw/993b76be5b714ca4b5de8acf95835c81.htm', 'https://www.nfu.edu.cn/xxyw/index.htm', 'https://www.nfu.edu.cn/rcpy/bkjy/index.htm', 'https://www.nfu.edu.cn/ztb/e9fc641fc5d347028808b3ba47ec099f.htm', 'http://jw.nfu.edu.cn/', 'https://www.nfu.edu.cn/xxyw/5d72606cd9244be2aaf87e33fadbdcdd.htm', 'https://www.nfu.edu.cn/xxyw/60bb79f3c6e645fb8c804b6e1a6f3c35.htm', 'http://lib.nfu.edu.cn/', 'https://www.nfu.edu.cn/', 'https://www.nfu.edu.cn/zjnf/index.htm', 'https://www.nfu.edu.cn/gjdt/c0546f17d79346a8b0526332862ac2f9.htm', 'https://www.nfu.edu.cn/jycg/e2234c554b4a4546aa6efffd6d42531f.htm', 'https://www.nfu.edu.cn/tzgg/6e3ca3ee8a4c4ae38a49ea806f017fa8.htm', 'https://www.nfu.edu.cn/zjnf/tsnf/index.htm', 'https://www.nfu.edu.cn/gjdt/index.htm', 'https://www.nfu.edu.cn/rcpy/msjs/index.htm', 'https://www.nfu.edu.cn/jycg/3e91076c0c1f441aaa1ff6d407ea47b2.htm', 'http://www.sysu.edu.cn/2012/cn/index.htm', 'http://gj.nfu.edu.cn/', 'https://www.nfu.edu.cn/xsjz/4d01c24d7d6446788b72363adb833a4e.htm', 'https://www.nfu.edu.cn/xxyw/90841c3eebff41a499c7adf3c9471692.htm', 'https://www.nfu.edu.cn/jxky/index.htm', 'https://www.nfu.edu.cn/tsg/index.htm', 'https://www.nfu.edu.cn/jycg/e31a222779844699bb775f6e90b9a61e.htm', 'https://www.nfu.edu.cn/xydt/9097b8c486d249beb27a85d23d057510.htm', 'http://www.gdmbjy.cn/', 'https://www.nfu.edu.cn/gjdt/840b1bbfaa76444e8647dcb5d2824722.htm', 'https://ershida.nfu.edu.cn/', 'https://www.nfu.edu.cn/xydt/210ae5d6a404496aa6600a7f195441c8.htm', 'https://www.nfu.edu.cn/mtnf/707537b9681e4d3bbe52104b77f4a01b.htm', 'https://www.nfu.edu.cn/ztb/index.htm', 'https://www.nfu.edu.cn/xsjz/index.htm', 'https://www.nfu.edu.cn/xxyw/415d61fa1f9f41e29fd7ee35e64acf36.htm', 'https://www.nfu.edu.cn/jycg/86044217245445f084c421ea6c300f2e.htm', 'https://www.nfu.edu.cn/xinxi/index.htm', 'http://zsb.nfu.edu.cn/', 'https://www.nfu.edu.cn/jycg/a515ee51daa04ffd8d208a144d784f87.htm', 'https://www.nfu.edu.cn/xxgk/xrld/index.htm', 'https://www.nfu.edu.cn/ztb/480fcc5e74114fbeb6ba749819464f22.htm', 'https://www.nfu.edu.cn/zjnf/ylfw/index.htm', 'https://www.nfu.edu.cn/xydt/2c3ae9a90a9d44ecbc8dd090ddf4c7fc.htm', 'http://das.nfu.edu.cn/', 'https://www.nfu.edu.cn/zjnf/shfw/index.htm', 'https://www.nfu.edu.cn/tzgg/de405112880f4acaa92c18da7d23af7e.htm', 'https://www.nfu.edu.cn/tzgg/index.htm', 'https://www.nfu.edu.cn/tzgg/fe70fb0a36e84c9d9d997c7ed302f882.htm', 'http://edu.gd.gov.cn/', 'https://www.nfu.edu.cn/yxnf1/yxnf/index.htm', 'http://en.nfu.edu.cn/', 'https://www.nfu.edu.cn/tzgg/cf024e1fb49042ed9af7612e47f525ef.htm', 'https://www.gpowersoft.com/', 'https://www.nfu.edu.cn/jycg/cc9fb843b6ff442ab911c97585ed070d.htm', 'https://www.nfu.edu.cn/index.htm', 'https://www.nfu.edu.cn/zjnf/jtzy/index.htm', 'https://www.nfu.edu.cn/zjnf/xb/index.htm', 'https://www.nfu.edu.cn/tzgg/4c55321c217b4e4587c30b816ec1d40a.htm', 'https://www.nfu.edu.cn/xxgk/xxjj/index.htm', 'https://www.nfu.edu.cn/xsjz/9d503e8889cb4121a19a6825bdaa25e7.htm', 'https://www.nfu.edu.cn/xxyw/c0b256a57c144bd3954ba7cbeff4efa3.htm', 'http://www.gdpr.com/', 'https://www.cnki.net/', 'https://www.nfu.edu.cn/jxky/kyjg/index.htm', 'https://www.nfu.edu.cn/rczp/index.htm', 'https://www.nfu.edu.cn/jycg/15b4a2a97b6e4cb08af99b3608e006ed.htm', 'https://www.nfu.edu.cn/ztb/095657e18243451eb90ed1a16d79d749.htm', 'https://www.nfu.edu.cn/zsjy/index.htm', 'https://www.nfu.edu.cn/ztb/3e672d87f8544a11930a436c11fdb4fe.htm', 'https://www.nfu.edu.cn/mtnf/92d4562302334422b7c21083b5301610.htm', 'https://www.nfu.edu.cn/jycg/a32d76179fba4d788a32d152c28b055c.htm', 'https://www.nfu.edu.cn/tzgg/894ac62a1d06411abada0b3de37866ba.htm', 'https://www.nfu.edu.cn/rcpy/jxjy/index.htm', 'https://www.nfu.edu.cn/ztb/b9065d0931004817bc95d98dbd54d732.htm', 'https://www.nfu.edu.cn/mtnf/50233f981b3840689c8b386f2d590828.htm', 'https://www.nfu.edu.cn/ztb/4a9e537abfac499fa779e1711fcf6444.htm', 'https://www.nfu.edu.cn/mtnf/index.htm', 'https://www.nfu.edu.cn/ztb/dfeb908c5e9f42308efc09df7f8fd9c1.htm', 'https://www.nfu.edu.cn/ztb/75a2c1db585b41278df8540181ce6fd5.htm', 'https://www.nfu.edu.cn/tzgg/9108102fc61d45d196e9eb23138d67aa.htm', 'https://www.nfu.edu.cn/gjdt/a78b679c97004ee587a80bf789c241f1.htm', 'https://www.nfu.edu.cn/rczp/jsxl/index.htm', 'https://www.nfu.edu.cn/ztb/b983ab5b8a07419988a8642b29a0e26a.htm', 'https://www.nfu.edu.cn/jycg/79f5045bbe6d4c96a70f70a75327539a.htm'}\n"
     ]
    }
   ],
   "source": [
    "# 获取页面上的所有链接，以绝对路径的方式。\n",
    "all_absolute_links = r.html.absolute_links\n",
    "print(all_absolute_links)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "275637c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过 CSS 选择器 来获取相应的内容文字\n",
    "o = session.get('https://news.cnblogs.com/')\n",
    "o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ae0802b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<Element 'a' href='/n/738519/' target='_blank'>,\n",
       " <Element 'a' href='/n/738518/' target='_blank'>,\n",
       " <Element 'a' href='/n/738517/' target='_blank'>,\n",
       " <Element 'a' href='/n/738516/' target='_blank'>,\n",
       " <Element 'a' href='/n/738515/' target='_blank'>,\n",
       " <Element 'a' href='/n/738514/' target='_blank'>,\n",
       " <Element 'a' href='/n/738513/' target='_blank'>,\n",
       " <Element 'a' href='/n/738512/' target='_blank'>,\n",
       " <Element 'a' href='/n/738511/' target='_blank'>,\n",
       " <Element 'a' href='/n/738510/' target='_blank'>,\n",
       " <Element 'a' href='/n/738509/' target='_blank'>,\n",
       " <Element 'a' href='/n/738508/' target='_blank'>,\n",
       " <Element 'a' href='/n/738507/' target='_blank'>,\n",
       " <Element 'a' href='/n/738506/' target='_blank'>,\n",
       " <Element 'a' href='/n/738505/' target='_blank'>,\n",
       " <Element 'a' href='/n/738504/' target='_blank'>,\n",
       " <Element 'a' href='/n/738503/' target='_blank'>,\n",
       " <Element 'a' href='/n/738502/' target='_blank'>,\n",
       " <Element 'a' href='/n/738500/' target='_blank'>,\n",
       " <Element 'a' href='/n/738501/' target='_blank'>,\n",
       " <Element 'a' href='/n/738499/' target='_blank'>,\n",
       " <Element 'a' href='/n/738498/' target='_blank'>,\n",
       " <Element 'a' href='/n/738497/' target='_blank'>,\n",
       " <Element 'a' href='/n/738496/' target='_blank'>,\n",
       " <Element 'a' href='/n/738495/' target='_blank'>,\n",
       " <Element 'a' href='/n/738494/' target='_blank'>,\n",
       " <Element 'a' href='/n/738493/' target='_blank'>,\n",
       " <Element 'a' href='/n/738492/' target='_blank'>,\n",
       " <Element 'a' href='/n/738491/' target='_blank'>,\n",
       " <Element 'a' href='/n/738490/' target='_blank'>]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过 类选择器名为 news_entry 的H2标签下面的 a 标签 输出文本内容\n",
    "news = o.html.find('h2.news_entry > a')\n",
    "news"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e9c8c319",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "百度吹的牛，能「一言」九鼎吗？\n",
      "{'https://news.cnblogs.com/n/738519/'}\n",
      "苹果上架官方新应用：用于测试某款配件是否兼容苹果设备\n",
      "{'https://news.cnblogs.com/n/738518/'}\n",
      "何小鹏：定价要更激进，明年小鹏整车动力和硬件系统成本降25%\n",
      "{'https://news.cnblogs.com/n/738517/'}\n",
      "性能革命！高通推出全新骁龙7系移动平台\n",
      "{'https://news.cnblogs.com/n/738516/'}\n",
      "魅族拿什么和苹果PK?\n",
      "{'https://news.cnblogs.com/n/738515/'}\n",
      "3年前逃离北京的年轻人，怎么又都回来了？\n",
      "{'https://news.cnblogs.com/n/738514/'}\n",
      "“蔚小理”年报：谁在天上，谁在坑里？\n",
      "{'https://news.cnblogs.com/n/738513/'}\n",
      "2023，电商“整顿”快递业\n",
      "{'https://news.cnblogs.com/n/738512/'}\n",
      "软件架构决策指北：怀疑主义的软件架构设计\n",
      "{'https://news.cnblogs.com/n/738511/'}\n",
      "从互联网汽车鼻祖坠落，荣威还能翻盘吗？\n",
      "{'https://news.cnblogs.com/n/738510/'}\n",
      "宝马首次公布新世代车型产品规划，2025年量产且至少推出6款车型\n",
      "{'https://news.cnblogs.com/n/738509/'}\n",
      "任正非透露华为自研ERP进展，谈及未来大模型趋势\n",
      "{'https://news.cnblogs.com/n/738508/'}\n",
      "“甩锅”两年后，唐岩回归难救陌陌\n",
      "{'https://news.cnblogs.com/n/738507/'}\n",
      "文心一言，接上了全民“宫廷玉液酒” 的暗号\n",
      "{'https://news.cnblogs.com/n/738506/'}\n",
      "抖音“老中医”，专治小红书\n",
      "{'https://news.cnblogs.com/n/738505/'}\n",
      "我卖二手特斯拉，两月亏50万\n",
      "{'https://news.cnblogs.com/n/738504/'}\n",
      "三星上线新网站 可查询手机是否采用OLED屏幕\n",
      "{'https://news.cnblogs.com/n/738503/'}\n",
      "王登科：这个世界变得更精彩，但好像也更无聊了\n",
      "{'https://news.cnblogs.com/n/738502/'}\n",
      "都是做游戏的，为何中国游戏圈的“AI恐惧症”最严重？\n",
      "{'https://news.cnblogs.com/n/738500/'}\n",
      "创新“水滴”外观设计，华为FreeBuds 5迎来全面升级，或将重新定义半入耳TWS标准！\n",
      "{'https://news.cnblogs.com/n/738501/'}\n",
      "腾讯投资二次元厂商库洛游戏：库洛将保持独立运营、《鸣潮》研发中\n",
      "{'https://news.cnblogs.com/n/738499/'}\n",
      "后左晖时代，贝壳转型走到哪一步了？\n",
      "{'https://news.cnblogs.com/n/738498/'}\n",
      "上市五年首次营收下滑，阅文还站得稳吗？\n",
      "{'https://news.cnblogs.com/n/738497/'}\n",
      "涨不动的工资：暴富过的Biotech，回到现实世界\n",
      "{'https://news.cnblogs.com/n/738496/'}\n",
      "拜腾汽车衰亡史：生于富贵，死于内斗\n",
      "{'https://news.cnblogs.com/n/738495/'}\n",
      "“三无”电影靠大学生群演出圈，短视频营销新解\n",
      "{'https://news.cnblogs.com/n/738494/'}\n",
      "孤胆李彦宏：虽千万人吾往矣\n",
      "{'https://news.cnblogs.com/n/738493/'}\n",
      "“作不死”的辛巴，是快手撕不掉的“土味”\n",
      "{'https://news.cnblogs.com/n/738492/'}\n",
      "杜绝315曝光的短信骗局，得要企业和平台出大力\n",
      "{'https://news.cnblogs.com/n/738491/'}\n",
      "东方甄选卖假野生虾？工作人员称被骗，供应商不认可“甩锅”\n",
      "{'https://news.cnblogs.com/n/738490/'}\n"
     ]
    }
   ],
   "source": [
    "# 通过输出的数据能够明显看出是一组数组 所以 便可以运用循环遍历的方法将其打印出来\n",
    "for i in news:\n",
    "    print(i.text)  # 获得新闻标题\n",
    "    print(i.absolute_links)  # 获得新闻链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "796e1da4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "百度吹的牛，能「一言」九鼎吗？\n",
      "「核心提示」 ChatGPT 一鸣惊人后，市场期待更能理解中文语义语境的产品出现，在万众瞩目中百度的“文心一言”3 月 16 日邀请测试，国内生成式 AI 到底什么水平？ 作者 宋子豪 编辑 邢昀 ChatGPT 一鸣惊人，成为人人讨论的话题之后，根植于中文市场，更理解中文语义语境和中国文化的产品什\n",
      "itwriter 投递  评论(0) 64 人浏览 文心一言 发布于 2023-03-18 11:46\n",
      "0\n",
      "苹果上架官方新应用：用于测试某款配件是否兼容苹果设备\n",
      "IT 之家 3 月 18 日消息，苹果近日在 App Store 上架了一款名为“Accessory Developer Assistant”的应用程序，用于测试某款配件是否兼容苹果设备。 报道称苹果公司正通过 Apple 开发者账户进行分发，但目前尚未列出。IT 之家的网友可以通过以下链接进行直接\n",
      "itwriter 投递  评论(0) 21 人浏览 苹果 发布于 2023-03-18 11:42\n",
      "0\n",
      "何小鹏：定价要更激进，明年小鹏整车动力和硬件系统成本降25%\n",
      "降本成了小鹏汽车 2023 年的新目标。 3 月 17 日，在小鹏汽车（XPEV.US；09868.HK）2022 年第四季度财报电话会上，小鹏汽车 CEO 何小鹏提的最多的一个关键词就是“降低成本”，“面对激烈的行业竞争和内卷，非常重要的是要有超强的成本控制能力，这也会是小鹏汽车接下来要赢得竞争的\n",
      "itwriter 投递  评论(0) 36 人浏览 何小鹏 小鹏汽车 发布于 2023-03-18 11:38\n",
      "0\n",
      "性能革命！高通推出全新骁龙7系移动平台\n",
      "3 月 17 日，高通正式宣布推出全新第二代骁龙7+ 移动平台。根据官方介绍，第二代骁龙7+ 凭借出色的 CPU 和 GPU 性能，支持持久流畅的游戏体验、动态暗光照片拍摄与 4K HDR 视频拍摄、AI 赋能的增强体验和高速 5G 与 Wi-Fi 连接，将为骁龙 7 系带来全面焕新的卓越体验。 有\n",
      "itwriter 投递  评论(0) 40 人浏览 高通 发布于 2023-03-18 11:32\n",
      "0\n",
      "魅族拿什么和苹果PK?\n",
      "燃次元（ID:chaintruth）原创 作者曹杨 编辑饶霞飞 高调“复出”的魅族，究竟还有多少人问津？ 3 月 14 日上午，魅族科技官方微博连发多条内容，为 3 月 30 日即将到来的发布会造势。 魅族科技先是在微博表示，“20 年前，以热爱为起点，探索行业创新的孤勇先锋；20 年后，以无界为彼\n",
      "itwriter 投递  评论(0) 40 人浏览 魅族 发布于 2023-03-18 11:25\n",
      "0\n",
      "3年前逃离北京的年轻人，怎么又都回来了？\n",
      "他们体悟了京外工作之后，兜兜转转又回到了革命老区，并在互联网上调侃自己是“回笼漂”。 文｜傻狍子 编｜ WEIFAN 文章来源｜三联生活实验室（ID：LIFELAB2020） 过去三年，北京有过大致可见的四波迁移潮。 2020 年底，有一批卷够了的年轻人抵达后海村，日浪夜酒，数字游民，过着一种类似嬉\n",
      "itwriter 投递  评论(0) 66 人浏览 发布于 2023-03-18 11:18\n",
      "1\n",
      "“蔚小理”年报：谁在天上，谁在坑里？\n",
      "深燃（shenrancaijing）原创 作者黎明 编辑魏佳 随着小鹏汽车在昨晚发布财务业绩，“蔚小理”都交出了 2022 年的答卷。 总体来说，三家公司在 2022 年都是增长的——发布了更多车型，卖掉了更多新车，获得了更多收入。但同时，无一例外的，它们的亏损也在扩大。 蔚来、理想的年收入都冲过了\n",
      "itwriter 投递  评论(0) 16 人浏览 蔚来 小鹏汽车 理想汽车 发布于 2023-03-18 11:00\n",
      "0\n",
      "2023，电商“整顿”快递业\n",
      "本文来自微信公众号“光子星球”（TMTweb）作者：何芙蓉编辑： 吴先之 “只给末端提需求，不给末端多分钱，服务质量是没法保证的。”晚上 9 点过，方林才结束一天的配送工作，拖着疲惫的身体将快递车开回驿站。 方林是广州一家菜鸟驿站的老板，自平台要求送货上门以来，他不得不承担起店内的配送工作，一般预留\n",
      "itwriter 投递  评论(0) 14 人浏览 顺丰 极兔 发布于 2023-03-18 10:53\n",
      "0\n",
      "软件架构决策指北：怀疑主义的软件架构设计\n",
      "人们普遍认为态度是成功的关键，这是有道理的。正如亨利·福特说的：“不管你认为自己是否能够做到——你都是对的。” 如果你不相信自己能做好一件事，而且不去尝试，就可能永远做不好，这一点似乎是显而易见的。 然而，只是相信自己能够做到也仅止步于此，准备和计划也很重要。 怀疑也是如此，但这是一种特定的类型，这\n",
      "itwriter 投递  评论(0) 20 人浏览 发布于 2023-03-18 10:40\n",
      "0\n",
      "从互联网汽车鼻祖坠落，荣威还能翻盘吗？\n",
      "文车圈能见度，作者刘媛媛 曾经靠着性价比打出一片天的上汽荣威，在年销量连续 4 年下滑的成绩面前，也开始慌了。 不久前，上汽荣威一口气向市场推出了两款新车——全新荣威 RX9 和 2023 款荣威 iMAX8，分别定价 17.58 万元～24.38 万元和 18.58 万元～25.58 万元，想借此\n",
      "itwriter 投递  评论(0) 17 人浏览 荣威 发布于 2023-03-18 10:32\n",
      "0\n",
      "宝马首次公布新世代车型产品规划，2025年量产且至少推出6款车型\n",
      "日前，宝马集团公布了其 2022 年财报数据，其中多项数据表现达到预期，尽管 2022 年仍旧面临了诸多具有挑战性的因素。2022 年，宝马集团总收入同比增长 28.2% 至 1426 亿欧元，其中净利润同比增长 49.1% 至 185.82 亿欧元。这让它超过老对手梅赛德斯-奔驰，成为 2022\n",
      "itwriter 投递  评论(0) 20 人浏览 宝马 发布于 2023-03-18 10:18\n",
      "0\n",
      "任正非透露华为自研ERP进展，谈及未来大模型趋势\n",
      "3 月 17 日消息，上海交通大学、西安电子科大学、南方科技大学、苏州大学等高校发布了一篇文章，内容为“擦亮花火、共创未来——任正非在‘难题揭榜’花火奖座谈会上的讲话”。 据了解，2 月 24 日，为感谢全国火花奖获奖学者对产业界及科学界做出的重大贡献，华为创始人任正非在深圳总部组织了部分获奖老师的\n",
      "itwriter 投递  评论(0) 57 人浏览 任正非 发布于 2023-03-18 10:10\n",
      "0\n",
      "“甩锅”两年后，唐岩回归难救陌陌\n",
      "文新立场 NewPosition，作者新立场 陌陌的风光，在 2018 年一场藏不住露富的团建中体现的淋漓尽致。 2018 年 8 月，陌陌全球 2000 多名员工，从北京、上海、成都、新德里、吉隆坡等多个城市出发，搭乘 82 架次航班到日本东京集中团建，一次性包下了当地 800 多间酒店客房… 这\n",
      "itwriter 投递  评论(0) 30 人浏览 唐岩 陌陌 发布于 2023-03-18 09:42\n",
      "0\n",
      "文心一言，接上了全民“宫廷玉液酒” 的暗号\n",
      "图片来源@视觉中国 文独角兽挖掘机，作者兽姐，编辑角叔 2023 年开年，人工智能领域华丽返场，以 ChatGPT 为代表的生成式 AI 接棒此前的 AlpgaGo，带着全新的故事重回世界舞台中央。 继微软投资的 OpenAI 实验室上线聊天机器人 ChatGPT 仅 4 个月后，国内科技企业百度也\n",
      "itwriter 投递  评论(0) 43 人浏览 文心一言 发布于 2023-03-18 09:30\n",
      "0\n",
      "抖音“老中医”，专治小红书\n",
      "本文来自微信公众号“虎嗅 APP”（huxiu_com）作者：黄青春 许多推倒重建，正在小红书内部发生。 3 月 10 日，《晚点 LatePost 》报道，小红书将再次提升直播业务为独立部门，统一管理直播内容与直播电商等业务，新部门负责人为银时（花名），同时也是小红书社区生态负责人。在此之前，小红\n",
      "itwriter 投递  评论(0) 37 人浏览 抖音 小红书 发布于 2023-03-18 09:07\n",
      "0\n",
      "我卖二手特斯拉，两月亏50万\n",
      "本文来自微信公众号“每人 Auto”（meirenauto）作者：那木编辑：李欢欢 特斯拉领降，小鹏、问界、理想、蔚来等跟进，比亚迪也坐不住了，暗中跟牌。2023 年新能源车怎么卷？车企以实际行动给出了答案——抢份额比保利润更重要。 城门失火，殃及池鱼。新车降价，二手车商囤积的新能源车瞬间成了“烫手\n",
      "itwriter 投递  评论(0) 47 人浏览 Tesla 发布于 2023-03-18 09:00\n",
      "0\n",
      "三星上线新网站 可查询手机是否采用OLED屏幕\n",
      "品玩 3 月 17 日讯，据 thetechoutlook 报道，三星近日上线了一个名为 OLED Era 的网页，可以为用户提供查询服务，让用户知道自己的手机型号是否采用三星的 OLED 屏幕。 用户可以从三星 Display 的网站跳转到这个页面，并通过输入手机品牌和型号来查询他们的手机是否使用\n",
      "itwriter 投递  评论(0) 40 人浏览 三星 发布于 2023-03-17 22:39\n",
      "3\n",
      "王登科：这个世界变得更精彩，但好像也更无聊了\n",
      "那是一个下午，办公室的咖啡机坏了，我在楼下买了一杯厚乳拿铁，上楼后发现同事都出去吃午饭了，我一个人坐在窗边的工位上，升起的阳光正好覆盖在了我的电脑屏幕上，浏览器的文字都变得模糊起来，我眯起眼睛，试图看清屏幕上的字，依稀能看到我的代码编辑器，正在用 post 方法请求 openai 的接口，heade\n",
      "itwriter 投递  评论(0) 62 人浏览 王登科 发布于 2023-03-17 22:38\n",
      "0\n",
      "都是做游戏的，为何中国游戏圈的“AI恐惧症”最严重？\n",
      "图片来源：Pixabay GameLook 报道/这段时间，游戏圈行媒利用 AI 吓唬从业者的声音甚嚣尘上，像是因 AI 导致美术团队优化，原画大量被裁的话题比比皆是。就行业风向来看，国内游戏业似乎集体患上了一种“AI 恐惧症”。 但有趣的是，在这个 AIGC 站上风口的新时代，网易最近却想要举办一\n",
      "itwriter 投递  评论(0) 51 人浏览 AI 发布于 2023-03-17 21:36\n",
      "0\n",
      "创新“水滴”外观设计，华为FreeBuds 5迎来全面升级，或将重新定义半入耳TWS标准！\n",
      "随着智能手机的普及和消费者对相应智能穿戴产品的需求增加，TWS 耳机市场迅速崛起，市场规模不断扩大，竞争日益激烈。 在 TWS 耳机市场中，虽然产品在不断的更新换代，但品牌往往只会在外观设计、音质、降噪等方面做出微小的改进，很少有产品能够带来真正意义上的突破创新，这导致了 TWS 耳机产品之间同质化\n",
      "itwriter 投递  评论(0) 90 人浏览 华为FreeBuds 发布于 2023-03-17 20:00\n",
      "0\n",
      "腾讯投资二次元厂商库洛游戏：库洛将保持独立运营、《鸣潮》研发中\n",
      "GameLook 报道/3 月 17 日消息，今日企查查信息显示，国内知名二次游戏厂商广州库洛科技有限公司近日发生工商变更，股东新增广西腾讯创业投资有限公司，同时公司注册资本由约 138.92 万人民币增至约 151.55 万人民币，交易完成后腾讯公司持有库洛游戏 14.33% 股份，库洛团队合计持\n",
      "itwriter 投递  评论(0) 21 人浏览 腾讯游戏 库洛游戏 发布于 2023-03-17 19:14\n",
      "0\n",
      "后左晖时代，贝壳转型走到哪一步了？\n",
      "文价值研究所 北京时间 3 月 16 日，贝壳发布了 2022 财年四季度及全年财报。由于市场早已调整好心理预期，这份成绩单并不叫人意外：营收、净利润同比下滑、GTV 缩水全都在意料之中。财报公布后，贝壳股价一度大涨逾 10%，也表明投资者的乐观态度。随着楼市逐步回暖，贝壳业绩大有希望实现反弹。 在\n",
      "itwriter 投递  评论(0) 20 人浏览 贝壳 发布于 2023-03-17 19:00\n",
      "0\n",
      "上市五年首次营收下滑，阅文还站得稳吗？\n",
      "文新立场 NewPosition，作者新立场 2023 年 3 月 16 日，阅文集团公布了截至 2022 年 12 月 31 日止 2022 年全年的经审核综合业绩。 2022 年，阅文总收入为人民币 76.3 亿元（约合 10.9 亿美元），较 2021 年同比下滑 12%，低于此前市场分析预估\n",
      "itwriter 投递  评论(0) 16 人浏览 阅文集团 发布于 2023-03-17 18:40\n",
      "1\n",
      "涨不动的工资：暴富过的Biotech，回到现实世界\n",
      "文氨基观察 2022 年以来，“降本增效”成了最流行的关键词，贵族投行也不例外。 过去一年，高盛、摩根大通这些顶级投行，最核心的工作之一，便是降本。两者均释放出了不仅会减少奖金，还会裁员的信号。 可以理解，错综复杂的形势，让投行们对未来的前景有所担忧，不得不未雨绸缪。不仅是投行，各行各业都是如此，严\n",
      "itwriter 投递  评论(0) 21 人浏览 发布于 2023-03-17 18:10\n",
      "0\n",
      "拜腾汽车衰亡史：生于富贵，死于内斗\n",
      "图片来源@拜腾汽车 文雷科技 Ieitech 新能源汽车行业一路走来，我们看到了蔚小理的辉煌，却忽视了更多车企的艰难求生并走向衰亡。可能是因为，失败者通常不需要太长时间，就会销声匿迹。 以铜为鉴，可正衣冠；以古为鉴，可知兴替；以人为鉴，可明得失。探究失败车企倒下的过程，可以避免后来者重蹈覆辙，只有吸\n",
      "itwriter 投递  评论(0) 18 人浏览 拜腾汽车 发布于 2023-03-17 17:55\n",
      "0\n",
      "“三无”电影靠大学生群演出圈，短视频营销新解\n",
      "文犀牛娱乐，坐着胖部，编辑朴芳 《大突围》，一部中小成本的抗战题材主旋律电影，完成了在社交媒体上的“突围”。 打开抖音搜索“大突围”，看到类似“电影没拍完群演先火了”、“大学生群演逼疯导演”、“毫无演技，全是感情”等关键词，你可能已经反应过来“原来是他们”。今年 2 月开始，抖音的@导演阿坤上传了一\n",
      "itwriter 投递  评论(0) 38 人浏览 发布于 2023-03-17 17:45\n",
      "0\n",
      "孤胆李彦宏：虽千万人吾往矣\n",
      "文锌财经，作者单一 讲百度之前，先来回顾一个大部分人并不算不陌生的故事。 《斯巴达 300 勇士》描述了人类史上最残酷的战争之一——温泉关之战。公元前 480 年，波斯国王薛西斯一世亲率 30 万大军出征希腊。而当时的希腊仍是城邦制，为抵御入侵，集结一支联军。 两军对垒的前线正是温泉关，由斯巴达城的\n",
      "itwriter 投递  评论(0) 39 人浏览 李彦宏 发布于 2023-03-17 17:33\n",
      "0\n",
      "“作不死”的辛巴，是快手撕不掉的“土味”\n",
      "文伯虎财经，作者 灵灵 辛巴又在揭快手的丑了。 3 月 8 日晚上，辛巴在直播间炮轰快手平台。他指责快手人气造假，并纵容情感主播演戏带货欺骗老人。还称一些直播间人气造假，10 万人写百万+，质问快手“造假为了给谁看，给资本市场看吗？” 连番炮轰后，辛巴直播间被快手封禁 48 小时，理由是“不符合社区\n",
      "itwriter 投递  评论(0) 45 人浏览 辛巴 发布于 2023-03-17 17:21\n",
      "0\n",
      "杜绝315曝光的短信骗局，得要企业和平台出大力\n",
      "文雷科技 Ieitech 又是一年 315，今年的晚会再次公布了一系列侵犯消费者权益的案例。其中，短信骗局的部分吸引了小雷的注意。生活在手机不离手时代的我们，似乎已经习惯了被各类短信、电话骚扰。但 315 公布的短信骗局中，受害者短短几分钟被盗刷十几万元的经历，听起来还是很触目惊心。 作为普通消费者\n",
      "itwriter 投递  评论(0) 21 人浏览 发布于 2023-03-17 17:12\n",
      "0\n",
      "东方甄选卖假野生虾？工作人员称被骗，供应商不认可“甩锅”\n",
      "文雷达财经，作者郑茜宛，编辑深海 没上今年央视 315 晚会的东方甄选，登上了微博热搜。 3 月 15 日，“东方甄选养殖虾当野生虾卖”的话题登上了热搜。据报道，江苏的消费者王先生在东方甄选直播间购买了董宇辉声称的“100% 野生海捕”大虾，可他发现这些虾其实是养殖的。而东方甄选的工作人员主动联系王\n",
      "itwriter 投递  评论(0) 38 人浏览 东方甄选 发布于 2023-03-17 16:55\n"
     ]
    }
   ],
   "source": [
    "a = o.html.find('div.news_block')\n",
    "a\n",
    "for j in a:\n",
    "    print(j.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0096a6a",
   "metadata": {},
   "source": [
    "# 体验项目三\n",
    "* 爬取网络图片 并进行保存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "bbbebcc6",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'bg/1p398w.jpg'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_12504\\1857189932.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     25\u001b[0m                                    \u001b[1;31m# eg.--> ['https','','th.wallhaen.cc','small','1p','1p3982.jpg']\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     26\u001b[0m \u001b[1;31m#     print(img_url,title)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 27\u001b[1;33m     \u001b[0msave_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_url\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtitle\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_12504\\1857189932.py\u001b[0m in \u001b[0;36msave_image\u001b[1;34m(url, title)\u001b[0m\n\u001b[0;32m      7\u001b[0m     \u001b[0mimg_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m)\u001b[0m     \u001b[1;31m# 定义一个变量名为 img_response 的函数其作用是利用 requests 发送请求，并get函数获取图片地址\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[1;31m#     print(img_response.content)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m     \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'bg/'\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtitle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'wb'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# 利用 with open（） as 打开指定文件夹（这里是名为bg的文件夹），并运用【wb】的模式 对文件夹进行写入内容（以byte形式将图片写入）\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     10\u001b[0m             \u001b[1;31m# wb:以二进制格式打开一个文件只用于写入。如果该文件已存在则将其覆盖。如果该文件不存在，创建新文件。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     11\u001b[0m         \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_response\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#write() 方法用于向文件中写入指定字符串。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'bg/1p398w.jpg'"
     ]
    }
   ],
   "source": [
    "from requests_html import HTMLSession\n",
    "import requests\n",
    "\n",
    "\n",
    "# 保存图片到bg/目录\n",
    "def save_image(url, title):     # 封装一个名为 save_image 的函数 且设置了 两个名字分别为 url 和 title 的形参\n",
    "    img_response = requests.get(url)     # 定义一个变量名为 img_response 的函数其作用是利用 requests 发送请求，并get函数获取图片地址\n",
    "#     print(img_response.content)\n",
    "    with open('bg/'+title, 'wb') as file: # 利用 with open（） as 打开指定文件夹（这里是名为bg的文件夹），并运用【wb】的模式 对文件夹进行写入内容（以byte形式将图片写入）\n",
    "            # wb:以二进制格式打开一个文件只用于写入。如果该文件已存在则将其覆盖。如果该文件不存在，创建新文件。\n",
    "        file.write(img_response.content) #write() 方法用于向文件中写入指定字符串。\n",
    "\n",
    "# 背景图片地址\n",
    "url = \"https://wallhaven.cc/\"\n",
    "\n",
    "session = HTMLSession()\n",
    "r = session.get(url)\n",
    "\n",
    "# 查找页面中背景图，找到链接，访问查看大图，并获取大图地址\n",
    "items_img = r.html.find('span.sm-thumb > a >img')     # 这里是找到相应的图片路径\n",
    "# print(items_img)\n",
    "for img in items_img:\n",
    "    img_url = img.attrs['src'] # 这里的img.attrs['src'] 意思是 利用 attrs 这个模块 去定义 src 这个链接名字 以此来提高爬取效率\n",
    "    title = img_url.split('/')[-1] # 这里的取名 是用split切片的形式 取 链接的最后一位\n",
    "                                   # eg.--> ['https','','th.wallhaen.cc','small','1p','1p3982.jpg']\n",
    "#     print(img_url,title)\n",
    "    save_image(img_url, title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "712b9de6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自己换个网站和文件夹进行尝试\n",
    "from requests_html import HTMLSession\n",
    "import requests\n",
    "\n",
    "\n",
    "# 保存图片到bg/目录\n",
    "def save_image(url, title):\n",
    "    img_response = requests.get(url)\n",
    "    print(img_response.content)\n",
    "    with open('test/'+title, 'wb') as file:\n",
    "        file.write(img_response.content)\n",
    "\n",
    "# 背景图片地址\n",
    "url = \"https://kanekikeh.online/\"\n",
    "\n",
    "session = HTMLSession()\n",
    "r = session.get(url)\n",
    "\n",
    "# 查找页面中背景图，找到链接，访问查看大图，并获取大图地址\n",
    "items_img = r.html.find('div.post-thumb > a >img')\n",
    "print(items_img)\n",
    "for img in items_img:\n",
    "    img_url = img.attrs['src']\n",
    "    title = 'test1'\n",
    "#     title = img_url.split('/')[-1]\n",
    "    print(img_url,title)\n",
    "    save_image(img_url, title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5eb84a7b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
